JsonObjectContract
Contract details for a Type used by the JsonSerializer.
using Newtonsoft.Json.Utilities;
using System;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security;
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);
}
[SecuritySafeCritical]
internal object GetUninitializedObject()
{
if (!JsonTypeReflector.FullyTrusted)
throw new JsonException("Insufficient permissions. Creating an uninitialized '{0}' type requires full trust.".FormatWith(CultureInfo.InvariantCulture, NonNullableUnderlyingType));
return FormatterServices.GetUninitializedObject(NonNullableUnderlyingType);
}
}
}