我有一个派生自可序列化类的类
[Serializable]
[XmlRoot("AccountPersonalizationData")]
public class AccountPersonalizationData : LookupKeyedCollection<Type, PersonalizedEntityState>
{
[XmlElement(ElementName="SavedProfiles")]
public string SavedProfiles { get; set; }
public AccountPersonalizationData() : base(GetKeyFromPersonalizedEntityState)
{
}
private static Type GetKeyFromPersonalizedEntityState(PersonalizedEntityState item)
{
return item.UnderlyingType;
}
}
LookupKeyedCollection派生自KeyedCollection
[XmlInclude(typeof(AccountPersonalizationData))]
public class LookupKeyedCollection<TKey, TItem> : KeyedCollection<TKey, TItem>
{
...
}
当我尝试序列化某些东西时,只有LookupKeyedCollection被序列化,而SavedProfiles属性却没有。
XmlSerializer serializer = new XmlSerializer(typeof(AccountPersonalizationData));
serializer.Serialize(xmlWriter, persData);