Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectContractResolver

Namespace: AdCodicem.ValueObjects.NewtonsoftJson
Assembly: AdCodicem.ValueObjects.NewtonsoftJson.dll

Resolves each value object, and its nullable type, to a contract carrying , and every other type through the resolver it wraps.

public sealed class ValueObjectContractResolver : IContractResolver

Inheritance​

object ← ValueObjectContractResolver

Implements​

IContractResolver

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

It is for code that hands Newtonsoft.Json a contract resolver alone, with no serializer settings to add the converter to: settings take instead, and neither that call nor AddValueObjectsNewtonsoftJson() wraps a resolver.

A type claims, which tells, nullable or not, a construction of a generic value object and a value object written by hand included, gets a of this resolver's own whose is the converter, kept for the resolver's lifetime. A contract of the wrapped resolver that carries a converter already, as one a [JsonConverter] on the type names, is answered as it is. The wrapped resolver's contracts are never changed: its cache may be shared by every instance of its type, as 's is.

The contract of a type holding value objects stays the wrapped resolver's, and Newtonsoft.Json keeps the contract of each of its members on it, from the first time a serializer reads or writes that member. A serializer over this resolver and another over the same wrapped resolver therefore see each other's member contracts, in whichever order they first run. Wrap a resolver no other serializer uses, as the parameterless constructor does: never MVC's default one, which is a single instance shared by every set of MVC's serializer settings in the process.

A contract's converter wins over the converters the serializer settings name: an application's own converter for a value object in loses to this one. Name it on the type with [JsonConverter] instead.

Given to a JSON Patch document of Microsoft.AspNetCore.JsonPatch as its ContractResolver, it is what the document converts a value with. JSON Patch reads the value again under settings of its own, which drop and , and replaces the converter's refusal with a message of its own, which quotes the value and carries no code. In MVC, ValueObjectJsonPatchExtensions.TryApplyTo, in AdCodicem.ValueObjects.AspNetCore.NewtonsoftJson, reads every value through the rules, with their codes, and needs no resolver.

Constructors​

ValueObjectContractResolver()​

Initializes a new instance of the class, wrapping a new of its own.

public ValueObjectContractResolver()

ValueObjectContractResolver(IContractResolver)​

Initializes a new instance of the class, wrapping a resolver, which every type but a value object keeps.

public ValueObjectContractResolver(IContractResolver inner)

Parameters​

inner IContractResolver

The resolver of every other type.

Exceptions​

ArgumentNullException

inner is null.

Properties​

Inner​

Gets the resolver it wraps.

public IContractResolver Inner { get; }

Property Value​

IContractResolver

Methods​

ResolveContract(Type)​

Resolves the contract for a given type.

public JsonContract ResolveContract(Type type)

Parameters​

type Type

The type to resolve a contract for.

Returns​

JsonContract

The contract for a given type.

Exceptions​

ArgumentNullException

type is null.