Edit

Share via


MessageEncoder.IsContentTypeSupported(String) Method

Definition

Returns a value that indicates whether a specified message-level content-type value is supported by the message encoder.

C#
public virtual bool IsContentTypeSupported(string contentType);

Parameters

contentType
String

The message-level content-type being tested.

Returns

true if the message-level content-type specified is supported; otherwise false.

Examples

The following code example shows how to override this method to handle different content types with the same media type.

C#
public override bool IsContentTypeSupported(string contentType)
{
    if (base.IsContentTypeSupported(contentType))
    {
        return true;
    }
    if (contentType.Length == this.MediaType.Length)
    {
        return contentType.Equals(this.MediaType, StringComparison.OrdinalIgnoreCase);
    }
    else
    {
        if (contentType.StartsWith(this.MediaType, StringComparison.OrdinalIgnoreCase)
            && (contentType[this.MediaType.Length] == ';'))
        {
            return true;
        }
    }
    return false;
}
C#
public class CustomTextMessageEncoderFactory : MessageEncoderFactory
{
    private MessageEncoder encoder;
    private MessageVersion version;
    private string mediaType;
    private string charSet;

    internal CustomTextMessageEncoderFactory(string mediaType, string charSet,
        MessageVersion version)
    {
        this.version = version;
        this.mediaType = mediaType;
        this.charSet = charSet;
        this.encoder = new CustomTextMessageEncoder(this);
    }

    public override MessageEncoder Encoder
    {
        get
        {
            return this.encoder;
        }
    }

    public override MessageVersion MessageVersion
    {
        get
        {
            return this.version;
        }
    }

    internal string MediaType
    {
        get
        {
            return this.mediaType;
        }
    }

    internal string CharSet
    {
        get
        {
            return this.charSet;
        }
    }
}

Remarks

This method is used to determine whether the message encoder can be used to read a particular style of message, based on its content-type. The information in the ContentType class is used to describe the data that is contained in a message and is used to determine if there is a content-type match.

A grammar that details the syntax of the content-type header is described in RFC 2045 Section 5.1. RFC 2046 provides detailed information on Multipurpose Internet Mail Extensions (MIME) media types and their parameters.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0