可能重复:
Public fields/properties of a class derived from BindingList<T> wont serialize
当我尝试序列化此对象时,只序列化了list属性。
目标代码:
public class checkList<T>: List<T>
{
public bool check = true;
public string path;
public string type;
}
我有一个要序列化的实例:
List<checkList<Keys>> hookKeys;
反序列化代码:
FileStream fs = new FileStream("list", FileMode.Open, FileAccess.Read);
XmlSerializer ser = new XmlSerializer(typeof(List<checkList<Keys>>));
hookKeys = (List<checkList<Keys>>)ser.Deserialize(fs);
fs.Close();
序列化代码:
FileStream fsK = new FileStream("list", FileMode.Create, FileAccess.Write);
XmlSerializer serK = new XmlSerializer(typeof(List<checkList<Keys>>));
serK.Serialize(fsK, (List<checkList<Keys>>)hookKeys);
fsK.Close();
序列化后的xml文件:
<ArrayOfArrayOfKeys xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ArrayOfKeys>
<Keys>X</Keys>
<Keys>Z</Keys>
<Keys>C</Keys>
</ArrayOfKeys>
</ArrayOfArrayOfKeys>
我如何序列化其他属性?