Table of Contents

Class TlumachDisplayNameResolver

Namespace
Tlumach.FluentValidation
Assembly
Tlumach.FluentValidation.dll

Provides the display names of properties from a Tlumach translation, for ValidatorOptions.Global.DisplayNameResolver.

For the property Name of the class Customer, the resolver looks up two keys: the type-qualified key {DisplayNamesGroup}.Customer.Name and the member key {DisplayNamesGroup}.Name. The type is the type of the object that FluentValidation validates (the root object). A name in the language of the message is preferred to a name in another language, so the first of these is returned:

  1. The text of the type-qualified key, found for the culture or its basic culture.
  2. The text of the member key, found for the culture or its basic culture.
  3. The text of the type-qualified key from the default file, or a text supplied by an OnTranslationValueNotFound handler.
  4. The text of the member key from the default file, or a text supplied by an OnTranslationValueNotFound handler.

When neither key has text, the resolver returns null, and FluentValidation uses its default name. A rule that calls WithName is not affected.

The name is read when the rule is validated, for the same culture as the messages of the language manager.

public sealed class TlumachDisplayNameResolver
Inheritance
TlumachDisplayNameResolver
Inherited Members

Constructors

TlumachDisplayNameResolver(TranslationManager, string?)

Initializes a new instance of the TlumachDisplayNameResolver class.

public TlumachDisplayNameResolver(TranslationManager translationManager, string? displayNamesGroup = "DisplayNames")

Parameters

translationManager TranslationManager

The translation manager that provides the names.

displayNamesGroup string

The group, in which the names are stored. null or empty for root keys.

Exceptions

ArgumentNullException

Thrown when translationManager is null.

Properties

DisplayNamesGroup

Gets the group, in which the names are stored.

public string? DisplayNamesGroup { get; }

Property Value

string

TranslationManager

Gets the translation manager that provides the names.

public TranslationManager TranslationManager { get; }

Property Value

TranslationManager

Methods

Resolve(Type, MemberInfo, LambdaExpression)

Returns the display name of the member. The signature matches ValidatorOptions.Global.DisplayNameResolver.

public string? Resolve(Type type, MemberInfo member, LambdaExpression expression)

Parameters

type Type

The type of the validated object.

member MemberInfo

The member being validated. May be null for rules that do not target a member.

expression LambdaExpression

The expression of the rule. Not used.

Returns

string

The display name, chosen as described in the summary of the class, or null when the translation has none.