Class DefaultContractResolver
Used by JsonSerializer to resolves a JsonContract for a given System.Type.
Implements
Inherited Members
Namespace: Bayat.Json.Serialization
Assembly: Bayat.Json.Runtime.dll
Syntax
public class DefaultContractResolver : IContractResolver
Constructors
| Improve this Doc View SourceDefaultContractResolver()
Initializes a new instance of the DefaultContractResolver class.
Declaration
public DefaultContractResolver()
DefaultContractResolver(Boolean)
Initializes a new instance of the DefaultContractResolver class.
Declaration
[Obsolete("DefaultContractResolver(bool) is obsolete. Use the parameterless constructor and cache instances of the contract resolver within your application for optimal performance.")]
public DefaultContractResolver(bool shareCache)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | shareCache | If set to |
Properties
| Improve this Doc View SourceDefaultMembersSearchFlags
Gets or sets the default members search flags.
Declaration
[Obsolete("DefaultMembersSearchFlags is obsolete. To modify the members serialized inherit from DefaultContractResolver and override the GetSerializableMembers method instead.")]
public BindingFlags DefaultMembersSearchFlags { get; set; }
Property Value
Type | Description |
---|---|
System.Reflection.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.
Declaration
public bool DynamicCodeGeneration { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IgnoreSerializableAttribute
Gets or sets a value indicating whether to ignore the System.SerializableAttribute attribute when serializing and deserializing types.
Declaration
public bool IgnoreSerializableAttribute { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IgnoreSerializableInterface
Gets or sets a value indicating whether to ignore the System.Runtime.Serialization.ISerializable interface when serializing and deserializing types.
Declaration
public bool IgnoreSerializableInterface { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Instance
Declaration
public static IContractResolver Instance { get; }
Property Value
Type | Description |
---|---|
IContractResolver |
SerializeCompilerGeneratedMembers
Gets or sets a value indicating whether compiler generated members should be serialized.
Declaration
public bool SerializeCompilerGeneratedMembers { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Methods
| Improve this Doc View SourceCanConvertToString(Type)
Declaration
public static bool CanConvertToString(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type |
Returns
Type | Description |
---|---|
System.Boolean |
CreateArrayContract(Type)
Creates a JsonArrayContract for the given type.
Declaration
protected virtual JsonArrayContract CreateArrayContract(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonArrayContract | A JsonArrayContract for the given type. |
CreateConstructorParameters(ConstructorInfo, JsonPropertyCollection)
Creates the constructor parameters.
Declaration
protected virtual IList<JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.ConstructorInfo | constructor | The constructor to create properties for. |
JsonPropertyCollection | memberProperties | The type's member properties. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IList<JsonProperty> | Properties for the given System.Reflection.ConstructorInfo. |
CreateContract(Type)
Determines which contract type is created for the given type.
Declaration
protected virtual JsonContract CreateContract(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonContract | A JsonContract for the given type. |
CreateDictionaryContract(Type)
Creates a JsonDictionaryContract for the given type.
Declaration
protected virtual JsonDictionaryContract CreateDictionaryContract(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonDictionaryContract | A JsonDictionaryContract for the given type. |
CreateDynamicContract(Type)
Creates a JsonDynamicContract for the given type.
Declaration
protected virtual JsonDynamicContract CreateDynamicContract(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonDynamicContract | A JsonDynamicContract for the given type. |
CreateISerializableContract(Type)
Creates a JsonISerializableContract for the given type.
Declaration
protected virtual JsonISerializableContract CreateISerializableContract(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonISerializableContract | A JsonISerializableContract for the given type. |
CreateLinqContract(Type)
Creates a JsonLinqContract for the given type.
Declaration
protected virtual JsonLinqContract CreateLinqContract(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonLinqContract | A JsonLinqContract for the given type. |
CreateMemberValueProvider(MemberInfo)
Creates the IValueProvider used by the serializer to get and set values from a member.
Declaration
protected virtual IValueProvider CreateMemberValueProvider(MemberInfo member)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MemberInfo | member | The member. |
Returns
Type | Description |
---|---|
IValueProvider | The IValueProvider used by the serializer to get and set values from a member. |
CreateObjectContract(Type)
Creates a JsonObjectContract for the given type.
Declaration
protected virtual JsonObjectContract CreateObjectContract(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonObjectContract | A JsonObjectContract for the given type. |
CreatePrimitiveContract(Type)
Creates a JsonPrimitiveContract for the given type.
Declaration
protected virtual JsonPrimitiveContract CreatePrimitiveContract(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonPrimitiveContract | A JsonPrimitiveContract for the given type. |
CreateProperties(Type, MemberSerialization)
Creates properties for the given JsonContract.
Declaration
protected virtual IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to create properties for. |
MemberSerialization | memberSerialization | The member serialization mode for the type. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IList<JsonProperty> | Properties for the given JsonContract. |
CreateProperty(MemberInfo, MemberSerialization)
Creates a JsonProperty for the given System.Reflection.MemberInfo.
Declaration
protected virtual JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MemberInfo | member | The member to create a JsonProperty for. |
MemberSerialization | memberSerialization | The member's parent MemberSerialization. |
Returns
Type | Description |
---|---|
JsonProperty | A created JsonProperty for the given System.Reflection.MemberInfo. |
CreatePropertyFromConstructorParameter(JsonProperty, ParameterInfo)
Creates a JsonProperty for the given System.Reflection.ParameterInfo.
Declaration
protected virtual JsonProperty CreatePropertyFromConstructorParameter(JsonProperty matchingMemberProperty, ParameterInfo parameterInfo)
Parameters
Type | Name | Description |
---|---|---|
JsonProperty | matchingMemberProperty | The matching member property. |
System.Reflection.ParameterInfo | parameterInfo | The constructor parameter. |
Returns
Type | Description |
---|---|
JsonProperty | A created JsonProperty for the given System.Reflection.ParameterInfo. |
CreateStringContract(Type)
Creates a JsonStringContract for the given type.
Declaration
protected virtual JsonStringContract CreateStringContract(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonStringContract | A JsonStringContract for the given type. |
GetClrTypeFullName(Type)
Declaration
public static string GetClrTypeFullName(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type |
Returns
Type | Description |
---|---|
System.String |
GetResolvedPropertyName(String)
Gets the resolved name of the property.
Declaration
public string GetResolvedPropertyName(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
Returns
Type | Description |
---|---|
System.String | Name of the property. |
GetSerializableMembers(Type)
Gets the serializable members for the type.
Declaration
protected virtual List<MemberInfo> GetSerializableMembers(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | The type to get serializable members for. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<System.Reflection.MemberInfo> | The serializable members for the type. |
GetState()
Declaration
public DefaultContractResolverState GetState()
Returns
Type | Description |
---|---|
DefaultContractResolverState |
IsIConvertible(Type)
Declaration
public static bool IsIConvertible(Type t)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t |
Returns
Type | Description |
---|---|
System.Boolean |
IsJsonPrimitiveType(Type)
Declaration
public static bool IsJsonPrimitiveType(Type t)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t |
Returns
Type | Description |
---|---|
System.Boolean |
ResolveContract(Type)
Resolves the contract for a given type.
Declaration
public virtual JsonContract ResolveContract(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to resolve a contract for. |
Returns
Type | Description |
---|---|
JsonContract | The contract for a given type. |
ResolveContractConverter(Type)
Resolves the default JsonConverter for the contract.
Declaration
protected virtual JsonConverter ResolveContractConverter(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | objectType | Type of the object. |
Returns
Type | Description |
---|---|
JsonConverter | The contract's default JsonConverter. |
ResolveDictionaryKey(String)
Resolves the key of the dictionary. By default ResolvePropertyName(String) is used to resolve dictionary keys.
Declaration
protected virtual string ResolveDictionaryKey(string dictionaryKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | dictionaryKey | Key of the dictionary. |
Returns
Type | Description |
---|---|
System.String | Resolved key of the dictionary. |
ResolvePropertyName(String)
Resolves the name of the property.
Declaration
protected virtual string ResolvePropertyName(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
Returns
Type | Description |
---|---|
System.String | Resolved name of the property. |