如何反序列化名称为关键字的属性
本文关键字:关键字 属性 反序列化 | 更新日期: 2023-09-27 18:16:15
我有以下XML代码:
<sees direction="NE"/>
<sees direction="E"/>
<sees direction="SE">
<object>diamond</object>
<background>green</background>
</sees>
<sees direction="SW">
<background>green</background>
</sees>
我对对象标签的反序列化有问题。首先手工编写属性,然后使用XSD工具生成类,还编辑了XMLElementAttribute。
System.Xml.Serialization.XmlElementAttribute("object", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string @object
{
get
{
return this.objectField;
}
set
{
this.objectField = value;
}
}
我没有找到方法来填充这个字段,甚至当它编译时,和所有其他字段(例如背景)工作良好。
我错过了什么吗?
您应该能够这样做:
[XmlElement("object")]
public string WhatEverNameYouLike {get; set;}