我正在使用 DataContractSerializer 进行序列化/反序列化。我需要忽略一个被序列化的实例的特定属性,该属性在另一个类中用作属性。在这里,我为您的参考提供了简单的代码结构。我尝试了 IgnoreDataMember 和 XmlIgnore 属性,但这些都没有用。
[DataContract(Name ="Sample")]
public class Sample1
{
[DataMember]
public Sample2 s2 { get; set; }
}
[KnownType("KnownTypes")]
public class Sample2
{
[DataMember]
public Sample3 s3 { get; set; }
}
public class Sample3
{
public string property1 { get; set; }
public string property2 { get; set; }
//No need to serialize this property while serializing "S3" property in "Sample2" class.
//Is it possible???
public string property3 { get; set; }
}