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

Class ValueObjectMessages

Namespace: AdCodicem.ValueObjects.Metadata
Assembly: AdCodicem.ValueObjects.Abstractions.dll

The keys and the arguments an application localises the message of a refused value object with: one key per rule code, and the arguments the rules the type declares supply.

public static class ValueObjectMessages

Inheritance​

object ← ValueObjectMessages

Inherited Members​

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

Remarks​

The message a rule refuses a value with is English, and stays so: and the logs are read by developers. An application that answers its users in their language looks a message up by the code of the rule instead, under the key gives it, ValueObject.value_object.too_short for and ValueObject.iban.check_digits for a code of its own. A key with no entry keeps the English message, so an application translates only what it wants to.

The arguments a message quotes come from the of the type that refused the value, the rules it declares once: a length, the bounds, the known values. Each has a name, which FluentValidation quotes as a placeholder, {MinLength}, and a position, from {1}, which an IStringLocalizer formats with ; {0} is the member the target reports the refusal under, which the target adds. The value refused is never an argument: a message shown to someone else must not quote what was sent.

The integrations look the messages up through this class: AddValueObjects(messages => …) on MVC, WithValueObjectProblemDetails(messages => …) on a minimal API, UseValueObjectProblemDetails(messages => …) on an Azure Functions HTTP trigger, AddValueObjects(options => options.UseResource<T>()) on a HotChocolate schema, AddValueObjectInputs(options => options.UseResource<T>()) for the inputs of a Blazor form, FluentValidation's LanguageManager under MustParseAs, MustSatisfy and NotDefault, and DataAnnotations' and under the resource their ErrorMessageResourceType names alone. It reads no annotation and closes no generic type at run time, so it runs in a native binary.

Fields​

KeyPrefix​

The prefix of every key, ValueObject., which keeps the keys of value objects together in a resource.

public const string KeyPrefix = "ValueObject."

Field Value​

string

Methods​

ArgumentsFor(ValueObjectDescriptor, string, IFormatProvider?)​

Gets the arguments a message for this code can quote, read from the schema of a descriptor and formatted for the culture.

public static IReadOnlyList<KeyValuePair<string, object?>> ArgumentsFor(ValueObjectDescriptor descriptor, string errorCode, IFormatProvider? provider)

Parameters​

descriptor ValueObjectDescriptor

The descriptor of the type that refused the value.

errorCode string

The code of the rule.

provider IFormatProvider?

Formats the numbers and the dates; null for .

Returns​

IReadOnlyList<KeyValuePair<string, object?>>

The name and the text of each argument, in the order of their positions from {1}; empty for a code other than , , and .

Remarks​

has MinLength, MaxLength, Minimum then Maximum, and KnownValues. Every value is text, never null: the empty text stands for a rule the schema does not declare, the other bound of a range that has one. Any other code, an application's own among them, has none.

A bound is held as invariant text, which is read back as the underlying type and written for the culture: 0.01 becomes 0,01 in French. Text the type cannot read, which a schema written by hand may hold, is kept as it is. The known values are written each for the culture and joined with the culture's list separator followed by a space, , in English and ; in French, where the comma separates the decimals.

The descriptor's schema may differ from the type's, when the application registered one by hand: its rules are those the integrations that read the registry enforce and publish.

Exceptions​

ArgumentNullException

descriptor or errorCode is null.

ArgumentException

errorCode is empty.

ArgumentsFor<TSelf, TValue>(string, IFormatProvider?)​

Gets the arguments a message for this code can quote, read from and formatted for the culture.

public static IReadOnlyList<KeyValuePair<string, object?>> ArgumentsFor<TSelf, TValue>(string errorCode, IFormatProvider? provider) where TSelf : struct, IValueObject<TSelf, TValue>

Parameters​

errorCode string

The code of the rule.

provider IFormatProvider?

Formats the numbers and the dates; null for .

Returns​

IReadOnlyList<KeyValuePair<string, object?>>

The name and the text of each argument, in the order of their positions from {1}; empty for a code other than , , and .

Type Parameters​

TSelf

The value object type that refused the value.

TValue

Its underlying type.

Remarks​

The arguments are those describes, read from the type's own schema, as a typed integration reads it, without asking the registry.

Exceptions​

ArgumentNullException

errorCode is null.

ArgumentException

errorCode is empty.

KeyFor(string)​

Gets the key of a rule code: followed by the code.

public static string KeyFor(string errorCode)

Parameters​

errorCode string

The code, one of or one of the application's own.

Returns​

string

The key, ValueObject.value_object.too_short for .

Exceptions​

ArgumentNullException

errorCode is null.

ArgumentException

errorCode is empty.

KeysFor(ValueObjectSchema, string)​

Gets the keys a message for a rule code is looked up under, the most specific first.

public static IReadOnlyList<string> KeysFor(ValueObjectSchema schema, string errorCode)

Parameters​

schema ValueObjectSchema

The rules of the type that refused the value.

errorCode string

The code of the rule.

Returns​

IReadOnlyList<string>

The keys, the first with an entry giving the message.

Remarks​

is the code of both bounds, and a message saying "between {1} and {2}" reads badly when the type declares one. For a schema declaring a minimum alone, the key of the code followed by .minimum comes first, ValueObject.value_object.out_of_range.minimum; for one declaring a maximum alone, followed by .maximum; then the key of the code. The key is chosen by the bounds the type declares, not by the side the value crossed, which a refusal does not tell. Any other case has the key of the code alone.

Exceptions​

ArgumentNullException

schema or errorCode is null.

ArgumentException

errorCode is empty.