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
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: ValueObject.value_object.too_short for
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 {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' 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
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
Remarks
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
descriptor or errorCode is null.
errorCode is empty.
ArgumentsFor<TSelf, TValue>(string, IFormatProvider?)
Gets the arguments a message for this code can quote, read from
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
Type Parameters
TSelf
The value object type that refused the value.
TValue
Its underlying type.
Remarks
The arguments are those
Exceptions
errorCode is null.
errorCode is empty.
KeyFor(string)
Gets the key of a rule code:
public static string KeyFor(string errorCode)
Parameters
errorCode string
The code, one of
Returns
The key, ValueObject.value_object.too_short for
Exceptions
errorCode is null.
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
The keys, the first with an entry giving the message.
Remarks
.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
schema or errorCode is null.
errorCode is empty.