我的结构类似于:
public class RootClass
{
public ClassB B { get; set; }
}
public class ClassB : MyCollection<Bitem>
{
private List<Bitem> _items = new List<Bitem>();
public override IEnumerable<Bitem> Items
{
get
{
return _items.AsReadOnly();
}
set
{
_items = value.ToList();
}
}
public int TheOtherMember { get;set; }
}
public abstract class MyCollection<T> : MyCollection, IEnumerable<T> where T : ItemBase
{
public abstract IEnumerable<T> Items { get; set; }
...........
}
public abstract class MyCollection
{
some properties ........
}
问题是当我序列化RootClass的一个实例时,文档中不存在TheOtherMember。
<RootClass>
<ClassB>
<Bitem>
<SomeBitemProperty ....>
</Bitem>
<Bitem>
<SomeBitemProperty ....>
</Bitem>
</ClassB>
</RootClass>
我希望得到类似的内容:
<RootClass>
<ClassB>
<Items>
<Bitem>
<SomeBitemProperty ....>
</Bitem>
<Bitem>
<SomeBitemProperty ....>
</Bitem>
</Items>
<TheOtherMember />
</ClassB>
</RootClass>
我尝试了许多xml属性的组合而没有运气。我错过了什么?