我有一個非常基本的類,它是子類的列表,以及一些摘要數據。 XmlSerializer不會序列化我的類中的所有內容
[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; }
}
...
// 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();
}
當我打電話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>
請注意,我有基本類型:List<Product>
。但是,我沒有任何的類屬性:標誌,A,B,C
難道我做錯了什麼?這是怎麼回事??
UPDATE感謝您的答覆。我不知道這是通過設計。我已經轉換爲BinaryFormatter(代替二進制序列化),它奇妙地工作。
-1:根本不起作用。 – 2011-02-21 19:03:25