[英]make XmlElement optional in c#
我使用REST(XML)進行客戶端-服務器通信。 給定的示例應從我的頻道中讀取。
[XmlRoot("Device")]
public class RestDevice
{
[DataMember]
[XmlElement("type")]
public string Type { get; set; }
}
我想使XmlElement“ type”為可選(這樣,如果根不包含1,我將獲得null作為RestDevice類的Type屬性。
我怎樣才能做到這一點?
[XmlElement(ElementName = "type", IsNullable = true)]
public string Type;
是您要找的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.