I have following 3 classes
public class MyMainClass
{
MyCollection<MyObject> m_oMyObjectCollection = null;
private string m_sID = string.Empty;
public MyCollection<MyObject> Collection
{
get
{
return this.m_oMyObjectCollection;
}
set
{
this.m_oMyObjectCollection = value;
}
}
[XmlAttribute]
public string ID
{
get
{
return this.m_sID;
}
set
{
this.m_sID = value;
}
}
}
public class MyCollection<T>:System.Collections.Generic.List<T>
{
private string m_sMyString=string.Empty;
[XmlAttribute]
public string @Default
{
get
{
return this.m_sMyString;
}
set
{
this.m_sMyString = value;
}
}
}
public class MyObject
{
string m_sID = string.Empty;
[XmlAttribute]
public string ID
{
get
{
return this.m_sID;
}
set
{
this.m_sID = value;
}
}
}
when I use XmlSerializer to serialize the object. the Default property
in the MyCollection class would not get serialized. The serialize code
I used as following:
MyCollection<MyObject> oCollection=new MyCollection<MyObject>();
oCollection.Default = "DEF001";
MyObject oMyObject = new MyObject();
oMyObject.ID = "ID001";
oCollection.Add(oMyObject);
MyMainClass oMain = new MyMainClass();
oMain.Collection = oCollection;
oMain.ID = "MAIN01";
XmlSerializer xs = new XmlSerializer(typeof(MyMainClass));
StringWriter sw = new StringWriter();
xs.Serialize(sw, oMain);
Debug.WriteLine(sw.ToString());
Could anyone please point out what I did wrong?
thanks
Jinsong