[英]make XmlElement optional in c#
I use REST (XML) for client-server communication. 我使用REST(XML)进行客户端-服务器通信。 The given example should be read from my Channel. 给定的示例应从我的频道中读取。
[XmlRoot("Device")]
public class RestDevice
{
[DataMember]
[XmlElement("type")]
public string Type { get; set; }
}
I would like to make the XmlElement "type" optional (so that if the root doesn't contain one, I will get null as the Type property of class RestDevice. 我想使XmlElement“ type”为可选(这样,如果根不包含1,我将获得null作为RestDevice类的Type属性。
How can I do that? 我怎样才能做到这一点?
[XmlElement(ElementName = "type", IsNullable = true)]
public string Type;
Is what you are looking for. 是您要找的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.