0
我都不再如下因素類:反序列化SortedSet:爲什麼項目需要實現IComparable?
[DataContract]
public class MyProject
{
[DataMember(Name = "Branches")]
private SortedSet<ModuleFilter> branches = new SortedSet<ModuleFilter>(new ModuleFilterComparer());
[DataMember(Name="VbuildFilePath")]
private string buildprogram = null;
}
我可以把它序列化到一個文件:
DataContractSerializer x = new DataContractSerializer(p.GetType());
using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(p.GetFilePath()))
{
x.WriteObject(writer, p);
}
但是當我嘗試與如下因素的代碼讀回,它失敗,除非我添加一個虛擬實現了IComparable到ModuleFilter對象
DataContractSerializer x = new DataContractSerializer(typeof(MyProject));
using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(filePath))
{
p = (MyProject)x.ReadObject(reader);
}
爲什麼沒有解串器使用的SortedSet成員所提供的IComparer?
謝謝