Table of Contents

Class TlumachEmailAddressAttribute

Namespace
Tlumach.DataAnnotations
Assembly
Tlumach.DataAnnotations.dll

An e-mail address validation attribute that takes its error message from a class created by Tlumach Generator.

The message template receives the display name of the member as {0}.

[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter, AllowMultiple = false)]
public sealed class TlumachEmailAddressAttribute : DataTypeAttribute, ITlumachLocalizedErrorMessage
Inheritance
TlumachEmailAddressAttribute
Implements
Inherited Members

Remarks

EmailAddressAttribute is sealed, so this attribute derives from DataTypeAttribute the way the sealed one does and delegates the check itself to an instance of it. The rule is therefore identical to the one of the framework and follows any future correction of it, and no expression from the framework is copied into Tlumach.

Constructors

TlumachEmailAddressAttribute()

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

public TlumachEmailAddressAttribute()

TlumachEmailAddressAttribute(Type, string)

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

public TlumachEmailAddressAttribute(Type translationClass, string translationKey)

Parameters

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.

IsValid(object?)

Tells whether the value is a valid e-mail address, using the rule of EmailAddressAttribute.

public override bool IsValid(object? value)

Parameters

value object

The value to check.

Returns

bool

true when the value is null or a valid e-mail address.