ContentTypeIsMimeType Method

Check if this instance of ContentType matches the specified MIME media type and subtype.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public bool IsMimeType(
	string mediaType,
	string mediaSubtype
)

Parameters

mediaType  String
The media type.
mediaSubtype  String
The media subtype.

Return Value

Boolean
if the ContentType matches the provided media type and subtype.

Remarks

If the specified mediaType or mediaSubtype are "*", they match anything.

Example

C#
                    public static void ProcessEntity (MimeEntity entity)
{
    var contentType = entity.ContentType;

    // IsMimeType() performs a case-insensitive comparison and supports "*" as a wildcard
    // for either the media type or the media subtype.
    if (contentType.IsMimeType ("text", "calendar")) {
        Console.WriteLine ("Found a calendar invitation.");
    } else if (contentType.IsMimeType ("text", "*")) {
        Console.WriteLine ("Found a text part with charset: {0}", contentType.Charset ?? "us-ascii");
    } else if (contentType.IsMimeType ("image", "*")) {
        Console.WriteLine ("Found an image: {0}", contentType.Name ?? "(unnamed)");
    } else if (contentType.IsMimeType ("multipart", "*")) {
        Console.WriteLine ("Found a multipart with boundary: {0}", contentType.Boundary);
    }
}
                  

Exceptions

ArgumentNullException

mediaType is .

-or-

mediaSubtype is .

See Also