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
countryCodestringThe ISO 3166-1 alpha-2 code, for example "TR".
errorMessagestringThe 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
Methods
IsValid(object?)
Determines whether the specified value of the object is valid.
public override bool IsValid(object? value)
Parameters
valueobjectThe value of the object to validate.
Returns
Exceptions
- InvalidOperationException
The current attribute is malformed.
- NotImplementedException
Neither overload of
IsValidhas 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
Returns
- bool
True if valid; otherwise false.