المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Serialization Question



C# Programming
05-12-2010, 03:40 AM
I have a series of classes that make up a hierarchy of objects. I am serializing the collection to an XML file: The top level is RuleRoot :

[Serializable]
[XmlRoot("Rules")]
public class RuleRoot
{
[XmlElement("Items")]
public List<RuleGroup> Groups { get; set; }

}

Then, in Groups I have:

[Serializable]
[XmlRoot("Group")]
public class RuleGroup
{
[XmlAttribute("ID")]
public int GroupID { get; set; }

[XmlAttribute("Name")]
public string GroupName { get; set; }

[XmlAttribute("Active")]
public bool Active { get; set; }

[XmlElement("Rules")]
public List<Rule> Rules { get; set; }
}

This all works fine. But now I want to base all of my classes off of a base class:

public abstract class _ItemBase
{
public ItemType Type
{
get;
internal set;
}

public int ItemId
{
get;
internal set;
}

private _Collection _Items = new _Collection();
public _Collection Items
{
get { return _Items; }
internal set { _Items = value; }
}
}

If I do this, then each object will inherit the Items collection, so in RuleRoot I no longer need Groups, and in RuleGroup I no longer
need Rules, and so on.

The question is, how do I then serialize this?
Everything makes sense in someone's mind