Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Serialization Question
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01464237
Message ID:
01464272
Vues:
26
Essentially you don't have to worry about it. You can't serialize a derived class in isolation anyway - all parent classes are also serialized (de-serialization wouldn't make any sense if this were not so)

Just make sure that any parent classes serialize their required properties.

>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<_ItemBase> _Items = new _Collection<_ItemBase>();
>        public _Collection<_ItemBase> 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?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform