Table of Contents

Class TlumachCompareAttribute

Namespace
Tlumach.DataAnnotations
Assembly
Tlumach.DataAnnotations.dll

A CompareAttribute that takes its error message from a class created by Tlumach Generator.

The message template receives the display name of the member as {0} and the display name of the other property as {1}, which is the order that CompareAttribute itself uses.

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public sealed class TlumachCompareAttribute : CompareAttribute, ITlumachLocalizedErrorMessage
Inheritance
TlumachCompareAttribute
Implements
Inherited Members

Examples

[TlumachCompare(nameof(Password), typeof(Strings), Strings.passwordMismatchKey)]
public string? ConfirmPassword { get; set; }

Constructors

TlumachCompareAttribute(string)

Initializes a new instance of the TlumachCompareAttribute class. Set TranslationClass and TranslationKey in the annotation, or leave both unset to behave exactly like CompareAttribute.

public TlumachCompareAttribute(string otherProperty)

Parameters

otherProperty string

The name of the property that the value is compared with.

TlumachCompareAttribute(string, Type, string)

Initializes a new instance of the TlumachCompareAttribute class that takes its message from the given translation.

public TlumachCompareAttribute(string otherProperty, Type translationClass, string translationKey)

Parameters

otherProperty string

The name of the property that the value is compared with.

translationClass Type

The class created by Tlumach Generator, or a nested group class inside one, that provides the message.

translationKey string

The name of the translation unit member in translationClass, or the key of a translation entry.

Properties

CultureSource

Gets the culture, for which the message is read.

public TranslationCultureSource CultureSource { get; set; }

Property Value

TranslationCultureSource

TranslationClass

Gets the class created by Tlumach Generator, or a nested group class inside one, that provides the message.

public Type? TranslationClass { get; set; }

Property Value

Type

TranslationKey

Gets the name of the translation unit member in TranslationClass, or the key of a translation entry.

public string? TranslationKey { get; set; }

Property Value

string

Methods

FormatErrorMessage(string)

Formats the error message, taking it from the configured translation when there is one.

public override string FormatErrorMessage(string name)

Parameters

name string

The display name of the member being validated. It becomes the {0} argument of the template.

Returns

string

The formatted message.

Exceptions

InvalidOperationException

Thrown when the Tlumach configuration of the attribute is invalid or the message cannot be resolved.