Serialization of an object and its Contained Objects
Posted
by Amit
on Stack Overflow
See other posts from Stack Overflow
or by Amit
Published on 2010-05-18T04:46:29Z
Indexed on
2010/05/18
5:00 UTC
Read the original article
Hit count: 225
xml-serialization
|c#
There is a main class having 2 subClasses(each represent separate entity) and all classes needs to be serialized.. how should I proceed ? My requirement is when I serelize MainClass, I should get the xml for each sub class and main class as well. Thanks in advance... and if my approach is incorrect... correct that as well..
Ex given below...
class MainClass
{
SubClass1 objSubclass1 = null;
SubClass2 objSubclass2 = null;
public MainClass()
{
objSubclass1 = new SubClass1();
objSubclass2 = new SubClass2();
}
[XmlElement("SubClass1")]
public SubClass1 SubClass1 {get {return objSubclass1;} }
[XmlElement("SubClass2")]
public SubClass2 SubClass2 {get {return objSubclass2;} }
}
Class SubClass1
{
Some properties here...
}
Class SubClass2
{
Some properties here...
}
© Stack Overflow or respective owner