Class DefaultContractResolver
- Namespace
- Newtonsoft.Json.Serialization
- Assembly
- Newtonsoft.Json.dll
Used by JsonSerializer to resolves a JsonContract for a given Type.
public class DefaultContractResolver : IContractResolver
- Inheritance
-
DefaultContractResolver
- Implements
- Derived
- Inherited Members
Constructors
DefaultContractResolver()
Initializes a new instance of the DefaultContractResolver class.
public DefaultContractResolver()
DefaultContractResolver(bool)
Initializes a new instance of the DefaultContractResolver class.
public DefaultContractResolver(bool shareCache)
Parameters
shareCacheboolIf set to
truethe DefaultContractResolver will use a cached shared with other resolvers of the same type. Sharing the cache will significantly performance because expensive reflection will only happen once but could cause unexpected behavior if different instances of the resolver are suppose to produce different results. When set to false it is highly recommended to reuse DefaultContractResolver instances with the JsonSerializer.
Properties
DefaultMembersSearchFlags
Gets or sets the default members search flags.
public BindingFlags DefaultMembersSearchFlags { get; set; }
Property Value
- BindingFlags
The default members search flags.
DynamicCodeGeneration
Gets a value indicating whether members are being get and set using dynamic code generation. This value is determined by the runtime permissions available.
public bool DynamicCodeGeneration { get; }
Property Value
- bool
trueif using dynamic code generation; otherwise,false.
SerializeCompilerGeneratedMembers
Gets or sets a value indicating whether compiler generated members should be serialized.
public bool SerializeCompilerGeneratedMembers { get; set; }
Property Value
- bool
trueif serialized compiler generated members; otherwise,false.
Methods
CreateArrayContract(Type)
Creates a JsonArrayContract for the given type.
protected virtual JsonArrayContract CreateArrayContract(Type objectType)
Parameters
objectTypeTypeType of the object.
Returns
- JsonArrayContract
A JsonArrayContract for the given type.
CreateConstructorParameters(ConstructorInfo, JsonPropertyCollection)
Creates the constructor parameters.
protected virtual IList<JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties)
Parameters
constructorConstructorInfoThe constructor to create properties for.
memberPropertiesJsonPropertyCollectionThe type's member properties.
Returns
- IList<JsonProperty>
Properties for the given ConstructorInfo.
CreateContract(Type)
Determines which contract type is created for the given type.
protected virtual JsonContract CreateContract(Type objectType)
Parameters
objectTypeTypeType of the object.
Returns
- JsonContract
A JsonContract for the given type.
CreateDictionaryContract(Type)
Creates a JsonDictionaryContract for the given type.
protected virtual JsonDictionaryContract CreateDictionaryContract(Type objectType)
Parameters
objectTypeTypeType of the object.
Returns
- JsonDictionaryContract
A JsonDictionaryContract for the given type.
CreateISerializableContract(Type)
Creates a JsonISerializableContract for the given type.
protected virtual JsonISerializableContract CreateISerializableContract(Type objectType)
Parameters
objectTypeTypeType of the object.
Returns
- JsonISerializableContract
A JsonISerializableContract for the given type.
CreateLinqContract(Type)
Creates a JsonLinqContract for the given type.
protected virtual JsonLinqContract CreateLinqContract(Type objectType)
Parameters
objectTypeTypeType of the object.
Returns
- JsonLinqContract
A JsonLinqContract for the given type.
CreateMemberValueProvider(MemberInfo)
Creates the IValueProvider used by the serializer to get and set values from a member.
protected virtual IValueProvider CreateMemberValueProvider(MemberInfo member)
Parameters
memberMemberInfoThe member.
Returns
- IValueProvider
The IValueProvider used by the serializer to get and set values from a member.
CreateObjectContract(Type)
Creates a JsonObjectContract for the given type.
protected virtual JsonObjectContract CreateObjectContract(Type objectType)
Parameters
objectTypeTypeType of the object.
Returns
- JsonObjectContract
A JsonObjectContract for the given type.
CreatePrimitiveContract(Type)
Creates a JsonPrimitiveContract for the given type.
protected virtual JsonPrimitiveContract CreatePrimitiveContract(Type objectType)
Parameters
objectTypeTypeType of the object.
Returns
- JsonPrimitiveContract
A JsonPrimitiveContract for the given type.
CreateProperties(Type, MemberSerialization)
Creates properties for the given JsonContract.
protected virtual IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
Parameters
typeTypeThe type to create properties for.
memberSerializationMemberSerializationThe member serialization mode for the type.
Returns
- IList<JsonProperty>
Properties for the given JsonContract.
CreateProperty(MemberInfo, MemberSerialization)
Creates a JsonProperty for the given MemberInfo.
protected virtual JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
Parameters
memberMemberInfoThe member to create a JsonProperty for.
memberSerializationMemberSerializationThe member's parent MemberSerialization.
Returns
- JsonProperty
A created JsonProperty for the given MemberInfo.
CreatePropertyFromConstructorParameter(JsonProperty, ParameterInfo)
Creates a JsonProperty for the given ParameterInfo.
protected virtual JsonProperty CreatePropertyFromConstructorParameter(JsonProperty matchingMemberProperty, ParameterInfo parameterInfo)
Parameters
matchingMemberPropertyJsonPropertyThe matching member property.
parameterInfoParameterInfoThe constructor parameter.
Returns
- JsonProperty
A created JsonProperty for the given ParameterInfo.
CreateStringContract(Type)
Creates a JsonStringContract for the given type.
protected virtual JsonStringContract CreateStringContract(Type objectType)
Parameters
objectTypeTypeType of the object.
Returns
- JsonStringContract
A JsonStringContract for the given type.
GetSerializableMembers(Type)
Gets the serializable members for the type.
protected virtual List<MemberInfo> GetSerializableMembers(Type objectType)
Parameters
objectTypeTypeThe type to get serializable members for.
Returns
- List<MemberInfo>
The serializable members for the type.
ResolveContract(Type)
Resolves the contract for a given type.
public virtual JsonContract ResolveContract(Type type)
Parameters
typeTypeThe type to resolve a contract for.
Returns
- JsonContract
The contract for a given type.
ResolveContractConverter(Type)
Resolves the default JsonConverter for the contract.
protected virtual JsonConverter ResolveContractConverter(Type objectType)
Parameters
objectTypeTypeType of the object.
Returns
ResolvePropertyName(string)
Resolves the name of the property.
protected virtual string ResolvePropertyName(string propertyName)
Parameters
propertyNamestringName of the property.
Returns
- string
Name of the property.