MessageEncoder.IsContentTypeSupported(String) MessageEncoder.IsContentTypeSupported(String) MessageEncoder.IsContentTypeSupported(String) MessageEncoder.IsContentTypeSupported(String) Method

定義

傳回值,這個值表示訊息編碼器是否支援指定的訊息層級內容類型值。Returns a value that indicates whether a specified message-level content-type value is supported by the message encoder.

public:
 virtual bool IsContentTypeSupported(System::String ^ contentType);
public virtual bool IsContentTypeSupported (string contentType);
abstract member IsContentTypeSupported : string -> bool
override this.IsContentTypeSupported : string -> bool
Public Overridable Function IsContentTypeSupported (contentType As String) As Boolean

參數

contentType
String String String String

正在測試的訊息層級內容類型。The message-level content-type being tested.

傳回

如果支援指定的訊息層級內容類型則為 true,否則為 falsetrue if the message-level content-type specified is supported; otherwise false.

範例

下列程式碼範例會示範如何覆寫這個方法,以處理具有相同媒體類型的不同內容類型。The following code example shows how to override this method to handle different content types with the same media type.

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; 
}
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;
        }
    }
}

備註

這個方法可以用來根據訊息的內容類型,判斷訊息編碼器是否可以用來讀取特定樣式的訊息。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. ContentType 類別中的資訊可用來描述包含在訊息中的資料,以及判斷是否有符合的內容類型。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.

詳細說明 content-type 標頭語法的文法所述RFC 2045第 5.1 節。A grammar that details the syntax of the content-type header is described in RFC 2045 Section 5.1. RFC 2046提供有關多用途網際網路郵件延伸標準 (MIME) 媒體類型及其參數的詳細的資訊。RFC 2046 provides detailed information on Multipurpose Internet Mail Extensions (MIME) media types and their parameters.

適用於