XmlAttributeAttribute 和 XmlElementAttribute
我想在属性上声明 XmlAttributeAttribute 和 XmlElementAttribute,以便 xml 正确反序列化,无论该属性是定义为 xml 元素还是 xml 属性。
例如 给定
public class X
{
[XmlElement()]
[XmlAttribute()]
public string Prop
{
get;
set;
}
}
以下任一条件,可以正确反序列化:
<X>
<Prop>XXX</Prop>
</X>
<X Prop="XXX"/>
这可能吗?
I'd like to declare both XmlAttributeAttribute and XmlElementAttribute on a property so that the xml deserializes correctly regardless of whether the property is defined as an xml element or as an xml attribute.
e.g.
given
public class X
{
[XmlElement()]
[XmlAttribute()]
public string Prop
{
get;
set;
}
}
either of the following deserialize correctly:
<X>
<Prop>XXX</Prop>
</X>
<X Prop="XXX"/>
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样引入转发属性
You can introduce a forwarding property like this