我有这门课
public class Audit
{
public string name { get; set;}
public DateTime AuditDate { get; set;}
public long? DepartmentId {get; set;}
public string Department { get; set;}
public long? StateId { get; set;}
public string? State { get; set; }
public long? CountryId { get; set; }
public string Country { get; set; }
}
当我序列化它看起来像这样
<Audit>
<name>George</name>
<AuditDate>01/23/2013</AuditDate>
<DepartmentId>10</DepartmentId>
<Department>Lost and Found</Department>
<StateId>15</StateId>
<State>New Mexico</StateId>
<CountryId>34</CountryId>
<Country>USA</Country>
</Audit>
我添加了这个类来尝试获取 id 字段作为属性
public class ValueWithId
{
[XmlAttribute ("id")]
public long? Id { get; set; }
[XmlText] // Also tried with [XmlElement]
public string Description { get; set; }
}
把我的课改写成这个
[Serializable]
public class Audit
{
public string name { get; set;}
public DateTime AuditDate { get; set;}
public ValueWithId Department { get; set;}
public ValueWithId State { get; set; }
public ValueWithId Country { get; set; }
}
但我收到错误“反映类型审核时出现错误”
我正在尝试将以下内容作为 XML
<Audit>
<name>George</name>
<AuditDate>01/23/2013</AuditDate>
<Department id=10>Lost and Found</Department>
<State id=15>New Mexico</State>
<Country id=34>USA</Country>
</Audit>
谢谢