I would like to remove properties based on a list of strings when serializing an object. I have tried to use DefaultContractResolver
, but it provides property.PropertyName
and nothing related to path or parent object:
public class Foo {
public Bar Bar {get;set;}
}
public class Bar {
public int MyProperty { get;set; }
public int MyProperty2 { get;set; }
public int MyProperty3 { get;set; }
}
var remove = new List<string> {
"Foo.Bar.MyProperty"
}
What is the best approach to serialize that object in a manner that Foo.Bar.MyProperty
will not be serialized?