我想 xml 序列化一个包含其他自定义对象的自定义对象。我像下面那样做,但它不会工作。
class A()
{
public B b;
}
class B()
{
public int a;
}
System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(A));
XmlAttributes xmlAttributes = new XmlAttributes();
System.IO.StreamWriter file = new System.IO.StreamWriter( @"d:\SerializationOverview.xml");
writer.Serialize(file, new A());
file.Close();
结果是:
<A>
</A>