Table of Contents

Class CountryValidationAttribute

Namespace
HeroKit.Validation
Assembly
HeroKit.dll

Base class for attributes that validate a string with the rules of a country registered in Countries.

public abstract class CountryValidationAttribute : ValidationAttribute
Inheritance
CountryValidationAttribute
Derived
Inherited Members
Extension Methods

Remarks

The country is resolved by its ISO code when a value is validated, so countries registered after the attribute was created are found. Null and empty values are valid; combine with RequiredAttribute to require a value. Non-string values are invalid.

Constructors

CountryValidationAttribute(string, string)

Initializes the attribute.

protected CountryValidationAttribute(string countryCode, string errorMessage)

Parameters

countryCode string

The ISO 3166-1 alpha-2 code, for example "TR".

errorMessage string

The default error message; "{0}" is the field name.

Properties

CountryCode

Gets the ISO 3166-1 alpha-2 code of the country.

public string CountryCode { get; }

Property Value

string

Methods

IsValid(object?)

Determines whether the specified value of the object is valid.

public override bool IsValid(object? value)

Parameters

value object

The value of the object to validate.

Returns

bool

true if the specified value is valid; otherwise, false.

Exceptions

InvalidOperationException

The current attribute is malformed.

NotImplementedException

Neither overload of IsValid has been implemented by a derived class.

IsValid(string, Country)

Validates a non-empty string with the rules of the country.

protected abstract bool IsValid(string value, Country country)

Parameters

value string

The value.

country Country

The resolved country.

Returns

bool

True if valid; otherwise false.