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
shareCache
boolIf set to
true
the 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
true
if 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
true
if serialized compiler generated members; otherwise,false
.
Methods
CreateArrayContract(Type)
Creates a JsonArrayContract for the given type.
protected virtual JsonArrayContract CreateArrayContract(Type objectType)
Parameters
objectType
TypeType 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
constructor
ConstructorInfoThe constructor to create properties for.
memberProperties
JsonPropertyCollectionThe 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
objectType
TypeType 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
objectType
TypeType 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
objectType
TypeType 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
objectType
TypeType 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
member
MemberInfoThe 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
objectType
TypeType 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
objectType
TypeType 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
type
TypeThe type to create properties for.
memberSerialization
MemberSerializationThe 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
member
MemberInfoThe member to create a JsonProperty for.
memberSerialization
MemberSerializationThe 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
matchingMemberProperty
JsonPropertyThe matching member property.
parameterInfo
ParameterInfoThe 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
objectType
TypeType 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
objectType
TypeThe 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
type
TypeThe 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
objectType
TypeType of the object.
Returns
ResolvePropertyName(string)
Resolves the name of the property.
protected virtual string ResolvePropertyName(string propertyName)
Parameters
propertyName
stringName of the property.
Returns
- string
Name of the property.