We\'re using JSON.net and want to use a consistent way to send and receive data (documents).
We want a base class that all documents will be derived from. The base c
Use the ShouldSerialize feature provided by Json.Net. So basically, your class will look like:
public abstract class JsonDocument
{
///
/// The document type that the concrete class expects to be deserialized from.
///
//[JsonProperty(PropertyName = "DocumentType")] // We substitute the DocumentType property with this ExpectedDocumentType property when serializing derived types.
public abstract string ExpectedDocumentType { get; }
///
/// The actual document type that was provided in the JSON that the concrete class was deserialized from.
///
public string DocumentType { get; set; }
//Tells json.net to not serialize DocumentType, but allows DocumentType to be deserialized
public bool ShouldSerializeDocumentType()
{
return false;
}
}