我想使用 System.Xml.Serialization 反序列化我的类,但我注意到使用 List Properties 的奇怪行为:
它从不调用 set 方法,这导致我丢失重要信息......
我想避免切换序列化方法。
public class Category
{
private string _name;
private List<Category> _subCategories;
private Category _parent;
public string Name
{
get { return _name; }
set { _name = value; }
}
public List<Category> SubCategories
{
get { return _subCategories; }
set
{
_subCategories = value;
foreach (Category category in _subCategories)
{
category.Parent = this;
}
}
}
[System.Xml.Serialization.XmlIgnoreAttribute]
public Category Parent
{
get { return _parent; }
set { _parent = value; }
}
}