I need to be able to control how/whether certain properties on a class are serialized. The simplest case is [ScriptIgnore]
. However, I only want these attributes to be honored for this one specific serialization situation I am working on - if other modules downstream in the application also want to serialize these objects, none of these attributes should get in the way.
So my thought is to use a custom attribute MyAttribute
on the properties, and initialize the specific instance of JsonSerializer with a hook that knows to look for that attribute.
At first glance, I don't see any of the available hook points in JSON.NET will provide the PropertyInfo
for the current property to do such an inspection - only the property's value. Am I missing something? Or a better way to approach this?
new
modifier when declaringInstance
?DefaultContractResolver
does not declare anInstance
member. Additionally, what is the purpose ofInstance
even being declared here? – Saire