我搜索了一会儿但没有找到答案。
我正在使用 DataContractSerializer 。是否可以跳过基本属性的序列化?
基类:
[KnownType(typeof(DerivedClass))]
[DataContract]
public class BaseClass
{
[DataMember(IsRequired = false)]
public virtual int BaseProperty{ get; set; }
//...
//Many other properties with [DataMember]
}
派生类:
[DataContract]
public class DerivedClass : BaseClass
{
// *** NO [DataMember] here***
public override int BaseProperty
{
get
{
throw new NotSupportedException("Does not apply");
}
set
{
throw new NotSupportedException("Does not apply");
}
}
}
在这种情况下,我看到错误消息:
System.Runtime.Serialization.SerializationException: 'Error in line 1 position 248...Expecting element 'BaseProperty'.