XmlMessageFormatter.CanRead(Message) 方法
定義
決定格式子是否能夠還原序列化訊息。Determines whether the formatter can deserialize the message.
public:
virtual bool CanRead(System::Messaging::Message ^ message);
public bool CanRead (System.Messaging.Message message);
abstract member CanRead : System.Messaging.Message -> bool
override this.CanRead : System.Messaging.Message -> bool
Public Function CanRead (message As Message) As Boolean
參數
傳回
如果 XML 格式子能夠還原序列化訊息,則為 true
,否則為 false
。true
if the XML formatter can deserialize the message; otherwise, false
.
實作
例外狀況
TargetTypeNames 和 TargetTypes 屬性都沒有設定。Neither the TargetTypeNames nor TargetTypes property has been set.
message
參數為 null
。The message
parameter is null
.
備註
當 CanRead 呼叫時,格式器會嘗試判斷訊息的內容是否為它可以還原序列化的東西。When CanRead is called, the formatter attempts to determine if the contents of the message are something it can deserialize. 如果訊息本文中的型別具有與和屬性所表示之陣列中的其中一個類型相同的架構,則格式器只能還原序列化訊息 TargetTypeNames TargetTypes 。The formatter can only deserialize the message if the type in the message body has the same schema as one of the types in the array represented by the TargetTypeNames and TargetTypes properties. CanRead 會 false
在下列兩種情況下傳回:CanRead returns false
under the following two circumstances:
未使用將訊息格式化 XmlMessageFormatter 。The message was not formatted using the XmlMessageFormatter.
訊息本文的架構不在或屬性中列出的內容中 TargetTypeNames TargetTypes 。The schema of the message body is not among those listed in either the TargetTypeNames or TargetTypes property.
TargetTypeNames和 TargetTypes 屬性會告知格式器必須能夠還原序列化的物件類型。The TargetTypeNames and TargetTypes properties tell the formatter what types of objects it must be able to deserialize. 如果清單中遺漏任何類型,但在訊息中找到,則會傳回 CanRead false
。If any type is missing from the list, yet is found within the message, CanRead returns false
.