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

Class InputValueObject<TValue>

Namespace: AdCodicem.ValueObjects.Blazor
Assembly: AdCodicem.ValueObjects.Blazor.dll

An input for a value object: reads the text a person types through the value object's rules, binds the normalized instance, shows the message of the rule that refuses it, and keeps the rule's code on the form's .

public class InputValueObject<TValue> : InputBase<TValue>, IComponent, IHandleEvent, IHandleAfterRender, IDisposable

Type Parameters​

TValue

The value object, or its nullable type.

Inheritance​

object ← ComponentBase ← InputBase<TValue> ← InputValueObject<TValue>

Implements​

IComponent, IHandleEvent, IHandleAfterRender, IDisposable

Inherited Members​

InputBase<TValue>.FormatValueAsString(TValue?), InputBase<TValue>.TryParseValueFromString(string?, out TValue, out string?), InputBase<TValue>.SetParametersAsync(ParameterView), InputBase<TValue>.Dispose(bool), InputBase<TValue>.AdditionalAttributes, InputBase<TValue>.Value, InputBase<TValue>.ValueChanged, InputBase<TValue>.ValueExpression, InputBase<TValue>.DisplayName, InputBase<TValue>.EditContext, InputBase<TValue>.FieldIdentifier, InputBase<TValue>.CurrentValue, InputBase<TValue>.CurrentValueAsString, InputBase<TValue>.CssClass, InputBase<TValue>.NameAttributeValue, ComponentBase.BuildRenderTree(RenderTreeBuilder), ComponentBase.OnInitialized(), ComponentBase.OnInitializedAsync(), ComponentBase.OnParametersSet(), ComponentBase.OnParametersSetAsync(), ComponentBase.StateHasChanged(), ComponentBase.ShouldRender(), ComponentBase.OnAfterRender(bool), ComponentBase.OnAfterRenderAsync(bool), ComponentBase.InvokeAsync(Action), ComponentBase.InvokeAsync(Func<Task>), ComponentBase.DispatchExceptionAsync(Exception), ComponentBase.SetParametersAsync(ParameterView), ComponentBase.RendererInfo, ComponentBase.Assets, ComponentBase.AssignedRenderMode, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

It renders a text <input>, as does, and reads its text through , the overload that reports the rule. Accepted text binds the instance the type creates, which the input then shows normalized. Refused text leaves the model as it was, stays in the field, marked invalid, and adds the rule's message to the form's validation messages, so that and show it and returns false; the code of the rule is read with . A message never quotes the text typed.

Empty text binds null to a nullable value object, which does before any parsing. On a value object that cannot be null, it is parsed as any other text: a type that accepts it, such as [ValueObject<string>(AllowEmpty = true)], binds the instance it creates, and a type that refuses it is answered with and the message [Required] gives, "The {0} field is required.", {0} being , or else the name of the field.

The text an instance shows is the text its type reads back: the value object's own text, written in the round-trip form of its underlying type (2026-10-14 for a date), and the bare underlying value, in that same form, for a type whose formatting hook writes something else. An instance equal to the default that its rules refuse, a field nobody filled in, shows as empty text; one they accept, a zero they allow, shows as its value.

The text is read and written in , or else in the current culture where the component is interactive, or prerenders for interactivity, and in the invariant culture under static rendering, which is the culture the framework reads a posted form in. A date, of a value object over , or , is read in the Gregorian calendar its text is written in, whatever the culture's own calendar: in th-TH or fa-IR, the culture's patterns and names stay, and a year typed is a Gregorian one. A statically rendered form is mapped by the framework, through , before any component runs: a refused value is then reported with the framework's own message, which quotes the text and carries no code.

The value object is found in , where a generated one is registered, or else, where the runtime supports dynamic code, described by reflection. Under native AOT, a value object written by hand and a construction of a generic one are registered by hand before the input renders; one the registry does not describe fails the first render with an naming the registration.

Properties​

Culture​

Gets or sets the culture the text is read and written in; when not set, the current culture where the component is interactive or prerenders for interactivity, the invariant one under static rendering.

[Parameter]
public CultureInfo? Culture { get; set; }

Property Value​

CultureInfo?

Element​

Gets or sets the associated .

[DisallowNull]
public ElementReference? Element { get; protected set; }

Property Value​

ElementReference?

SchemaAttributes​

Gets or sets a value indicating whether the input carries the maxlength, minlength and pattern attributes the value object's rules give; off by default, since a browser checks the text as it is typed, before the value object's normalizer runs.

[Parameter]
public bool SchemaAttributes { get; set; }

Property Value​

bool

Remarks​

The lengths are counted in UTF-16 code units, by the browser as by .NET. The pattern is written only when a browser, which compiles it with the v flag and matches it against the whole text, accepts every text the .NET pattern accepts: a pattern each of whose alternatives is anchored at both ends, with no ., negated class or escape, word boundary, class subtraction, surrogate, named block or category C or Cs, and nothing the shared reader of .NET patterns refuses, such as a lookaround; \d, \w, \s and \p{…} are written as the characters .NET matches them with. The attributes are written the first time an input of the type asks for them. An attribute the input is given explicitly wins over the one the rules give.

Methods​

BuildRenderTree(RenderTreeBuilder)​

Renders the component to the supplied .

protected override void BuildRenderTree(RenderTreeBuilder builder)

Parameters​

builder RenderTreeBuilder

A that will receive the render output.

Dispose(bool)​

protected override void Dispose(bool disposing)

Parameters​

disposing bool

FormatValueAsString(TValue?)​

Formats the value as a string. Derived classes can override this to determine the formatting used for .

protected override string? FormatValueAsString(TValue? value)

Parameters​

value TValue?

The value to format.

Returns​

string?

A string representation of the value.

Remarks​

formats the model's value only while no refused text shows, so the code of an earlier refusal is cleared here too, whichever way the text was set. A subclass that sets to empty text on a nullable value object reaches no member of the input before the form notifies the change, which still reads the earlier code; the change event clears it first.

TryParseValueFromString(string?, out TValue, out string?)​

Parses a string to create an instance of TValue. Derived classes can override this to change how interprets incoming values.

protected override bool TryParseValueFromString(string? value, out TValue result, out string? validationErrorMessage)

Parameters​

value string?

The string value to be parsed.

result TValue

An instance of TValue.

validationErrorMessage string?

If the value could not be parsed, provides a validation error message.

Returns​

bool

True if the value could be parsed; otherwise false.