提问人:Rick de Water 提问时间:10/20/2023 更新时间:10/20/2023 访问量:17
内联 XML 元素
Inlining XML elements
问:
我有以下型号:
public PersonInfo
{
[XmlElement("initials")]
public string Initials { get; set; }
[XmlElement("prefix")]
public string Prefix { get; set; }
[XmlElement("familyName")]
public string FamilyName { get; set; }
}
public ContactPerson
{
[XmlElement("department")]
public string Department { get; set; }
public PersonInfo PersonInfo { get; set; }
}
public Driver
{
[XmlElement("vehicleID")]
public string VehicleId { get; set; }
public PersonInfo PersonInfo { get; set; }
}
有没有办法在序列化时内联属性,以便我得到PersonInfo
XmlSerializer
<contactPerson>
<department>SillyWalks</department>
<initials>J</initials>
<familyName>Time</familyName>
</contactPerson>
而不是
<contactPerson>
<department>SillyWalks</department>
<PersonInfo>
<initials>J</initials>
<familyName>Time</familyName>
</PersonInfo>
</contactPerson>
继承不是一种选择,因为我有多个这样的模型需要内联。
答: 暂无答案
评论