I know that Json.NET supports conditional serialization using ShouldSerialize{PropName}
But is there any way to prevent an entire type to be serialized w/o changing the type that references it? e.g.
public class Foo
{
public bool Enabled {get;set;}
...other properties
}
public class Bar
{
public Foo SomeFoo {get;set;}
public Foo OtherFoo {get;set;}
}
I want the Bar type to not include SomeFooo or OtherFoo depending on if the Enabled property is set. if SomeFoo.Enabled = false, then Bar.SomeFoo should not be serialized.
So I want a conditional serialization for a referencing property. And I don't want the consume of the Foo type to have any extra code or attribs. it should all go in the Foo type.
I could add a ShouldSerializeSomeFoo in Bar.. but that is not what I'm looking for..