.net - Serialize C# Objects while maintaining object references -
so have multiple custom classes referencing other classes in instances. know how serialization works in general, how deal object references? goal save objects in either xml or binary state can restored later.
in simplified example persons identified id , have list of other person objects referenced called friends.
public class person{ public int id; public list<person> friends; }
how serialize , deserialize example , keep object references intact? think deserialization can tricky if it's trying restore refernces persons haven't been deserialized yet.
[xmlrootattribute("person")] public class person{ [xmlattribute("_id")] public int id; [xmlelement("friends")] public list<person> friends; }
and use xmlserializer class create xml file , / or object https://msdn.microsoft.com/en-us/library/58a18dwa.aspx
Comments
Post a Comment