Table of Contents

Class TlumachRangeAttribute

Namespace
Tlumach.DataAnnotations
Assembly
Tlumach.DataAnnotations.dll

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

The message template receives the display name of the member as {0}, Minimum as {1} and Maximum as {2}, which is the order that RangeAttribute itself uses.

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

Constructors

TlumachRangeAttribute(double, double)

Initializes a new instance of the TlumachRangeAttribute class for a range of double-precision values. Set TranslationClass and TranslationKey in the annotation, or leave both unset to behave exactly like RangeAttribute.

public TlumachRangeAttribute(double minimum, double maximum)

Parameters

minimum double

The lowest allowed value.

maximum double

The highest allowed value.

TlumachRangeAttribute(double, double, Type, string)

Initializes a new instance of the TlumachRangeAttribute class for a range of double-precision values, taking its message from the given translation.

public TlumachRangeAttribute(double minimum, double maximum, Type translationClass, string translationKey)

Parameters

minimum double

The lowest allowed value.

maximum double

The highest allowed value.

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.

TlumachRangeAttribute(int, int)

Initializes a new instance of the TlumachRangeAttribute class for a range of integers. Set TranslationClass and TranslationKey in the annotation, or leave both unset to behave exactly like RangeAttribute.

public TlumachRangeAttribute(int minimum, int maximum)

Parameters

minimum int

The lowest allowed value.

maximum int

The highest allowed value.

TlumachRangeAttribute(int, int, Type, string)

Initializes a new instance of the TlumachRangeAttribute class for a range of integers, taking its message from the given translation.

public TlumachRangeAttribute(int minimum, int maximum, Type translationClass, string translationKey)

Parameters

minimum int

The lowest allowed value.

maximum int

The highest allowed value.

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.

TlumachRangeAttribute(Type, string, string)

Initializes a new instance of the TlumachRangeAttribute class for a range of values of an arbitrary comparable type. Set TranslationClass and TranslationKey in the annotation as named properties.

public TlumachRangeAttribute(Type operandType, string minimum, string maximum)

Parameters

operandType Type

The type of the values being compared.

minimum string

The lowest allowed value, as text.

maximum string

The highest allowed value, as text.

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 range of the attribute is illegal, when the Tlumach configuration of the attribute is invalid, or when the message cannot be resolved.