Jer*_*rry 1 c# ienumerable list xml-serialization
我有一个非常基本的类,它是一个子类列表,加上一些摘要数据.
[Serializable]
public class ProductCollection : List<Product>
{
public bool flag { get; set; }
public double A { get; set; }
public double B { get; set; }
public double C { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
...
// method to save this class
private void SaveProductCollection()
{
// Export case as XML...
XmlSerializer xml = new XmlSerializer(typeof(ProductCollection));
StreamWriter sw = new StreamWriter("output.xml");
xml.Serialize(sw, theCollection);
sw.Close();
}
Run Code Online (Sandbox Code Playgroud)
SaveProductCollection()我得到以下内容:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfProduct xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Product>
<InputType>1</InputType>
</Product>
<Product>
<InputType>1</InputType>
</Product>
</ArrayOfProduct>
Run Code Online (Sandbox Code Playgroud)
List<Product>.但是我没有任何类属性:flag,A,B,C.
我做错什么了吗?这是怎么回事??
更新感谢您的回复.我不知道它是按设计的.我已经转换为BinaryFormatter(用于二进制序列化),它运行得非常好.