gpt4 book ai didi

c# - 带有 XML 序列化的不需要的属性名称

转载 作者:数据小太阳 更新时间:2023-10-29 02:14:38 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Removing Wrapper Elements from XML-Serialized Array

这很难解释,所以我提供了一个问题示例。我有一个包含子类列表的父类。当我序列化父类时,我得到了我的子类,但它们位于具有公共(public)属性名称的元素下。额外的水平不是我需要的。我尝试将 XmlIgnore 属性添加到属性名称,但这抑制了属性名称及其包含的发票集合的所有内容。

父类:

[XmlRoot("header")]
public class Lynx : INotifyPropertyChanged
{

#region /*-- Class Fields --*/

private List<InvoiceItem> _invoice = new List<InvoiceItem>();

#endregion

[XmlArray("invoice")]
[XmlArrayItem("invoice", typeof(InvoiceItem))]
public List<InvoiceItem> invoice
{
get
{
return _invoice;
}
set
{
if (value != _invoice)
{
_invoice = value;
OnPropertyChanged("invoice");
}
}
}

子类:

[XmlType(TypeName = "invoice")]
public class InvoiceItem : INotifyPropertyChanged
{
... properties and methods of the class
}

这是它正在构建的:

<header>
<headerid>790aa61a-ad1b-49b9-bfb9-01fe3ca55eca</headerid>
<invoice> <-- this line is not needed
<invoice>
<company>BRU111</company>
<format>myformat</format>
...

这是我需要构建的:

<header>
<headerid>790aa61a-ad1b-49b9-bfb9-01fe3ca55eca</headerid>
<invoice>
<company>BRU111</company>
<format>myformat</format>
...

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com