【发布时间】:2021-04-13 09:04:47
【问题描述】:
我需要创建一个序列化为此的对象模型:
<RootItem>
<PropertySet name="SomePropList">
<Property name="SomeProp" value="SomeValue"/>
</PropertySet>
</RootItem>
我想不通。我有以下内容:
[XmlRoot("RootItem")]
public class RootItem
{
public AuthResponse()
{
PropertySet = new PropertySet();
}
public PropertySet PropertySet { get; set; }
}
public class PropertySet : List<Property>
{
public PropertySet()
{
}
[XmlAttribute]
public string name { get; set; }
}
[XmlType("Property")]
public class Property
{
[XmlAttribute]
public string name { get; set; }
[XmlAttribute]
public string value { get; set; }
}
不幸的是,当它序列化时,它忽略了 name 属性,而我得到了这个:
<RootItem>
<PropertySet>
<Property name="externalId" value="55555555"/>
</PropertySet>
</RootItem>
我需要什么类型的对象模型/技巧/属性才能使用 PropertySet 中的 name 属性进行序列化?
【问题讨论】:
标签: c# xml .net-core serialization