I’m using DataContractSerializer for serialization/deserialization. I need to ignore a particular property of an instance gets serialized which used as a property in another class. Here I have provided the simple code structure for your references. I have tried IgnoreDataMember and XmlIgnore attributes, but these not worked.
[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; }
}