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

Class ValueObjectInputConverter

Namespace: AdCodicem.ValueObjects.AzureFunctions
Assembly: AdCodicem.ValueObjects.AzureFunctions.dll

Binds a value object from the text of a route value, a query value or other binding data, through its TryParse.

public sealed class ValueObjectInputConverter : IInputConverter

Inheritance​

object ← ValueObjectInputConverter

Implements​

IInputConverter

Inherited Members​

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

Remarks​

The isolated worker reads no [TypeConverter]: without this converter, the text of a value object falls through to the worker's JSON conversion, which refuses a valid Guid, string or DateOnly and fails every such invocation. puts this converter first among the worker's registered converters, or right behind the ASP.NET Core integration's, which binds an HttpRequest and an HttpRequestData alone.

It reads a parameter whose type, unwrapped, is a value object the registry describes, and whose source is text: the text is parsed as it stands, then, when that fails and it is a JSON string literal, as the string it encodes, since the host sends binding data of another type than as JSON, and, for a value object over , when it is a JSON number, as the number the worker's JSON conversion reads, an exponent included, which a decimal's TryParse refuses. Empty text is parsed too, and refused by the type's own rule. A parameter with no binding data is left to the worker, which binds null to a nullable value object and its default value to an optional one, and fails a required one itself. A parameter carrying an input or trigger binding attribute is left to that binding and to the worker's serializer, which honours the generated JSON converter: naming this converter on the parameter with [InputConverter(typeof(ValueObjectInputConverter))] reads a raw-text payload instead, and one that names another converter is left to it.

A refusal is with a whose message names the type, the rule and its code, and whose holds the code under ; neither holds the refused text. The worker keeps only the exception's text, in the FunctionInputConverterException it throws, which is why the message carries the code.

A generated value object registers itself; a value object written by hand and a construction of a generic one are described by reflection where the runtime supports dynamic code, and otherwise once registered by hand. Only the types described are kept, so that one registered after a first miss is read from then on.

Methods​

ConvertAsync(ConverterContext)​

Parses the text the host bound to the parameter, or leaves the parameter to the next converter.

public ValueTask<ConversionResult> ConvertAsync(ConverterContext context)

Parameters​

context ConverterContext

The parameter's conversion context.

Returns​

ValueTask<ConversionResult>

The value object, a failure carrying the rule's code, or for a parameter that is not this converter's.

Exceptions​

ArgumentNullException

context is null.