JsonObjectContract
Contract details for a Type used by the JsonSerializer.
using System;
using System.Reflection;
namespace Newtonsoft.Json.Serialization
{
public class JsonObjectContract : JsonContainerContract
{
private bool? _hasRequiredOrDefaultValueProperties;
public MemberSerialization MemberSerialization { get; set; }
public Required? ItemRequired { get; set; }
public JsonPropertyCollection Properties { get; set; }
public JsonPropertyCollection ConstructorParameters { get; set; }
public ConstructorInfo OverrideConstructor { get; set; }
public ConstructorInfo ParametrizedConstructor { get; set; }
public ExtensionDataSetter ExtensionDataSetter { get; set; }
public ExtensionDataGetter ExtensionDataGetter { get; set; }
internal bool HasRequiredOrDefaultValueProperties {
get {
if (!_hasRequiredOrDefaultValueProperties.HasValue) {
_hasRequiredOrDefaultValueProperties = false;
if (ItemRequired.GetValueOrDefault(Required.Default) != 0)
_hasRequiredOrDefaultValueProperties = true;
else {
foreach (JsonProperty property in Properties) {
if (property.Required != 0 || (((int?)property.DefaultValueHandling & 2) == 2 && property.Writable)) {
_hasRequiredOrDefaultValueProperties = true;
break;
}
}
}
}
return _hasRequiredOrDefaultValueProperties.Value;
}
}
public JsonObjectContract(Type underlyingType)
: base(underlyingType)
{
ContractType = JsonContractType.Object;
Properties = new JsonPropertyCollection(base.UnderlyingType);
ConstructorParameters = new JsonPropertyCollection(base.UnderlyingType);
}
}
}