Class CountryCode
- Namespace
- Trellis.Primitives
- Assembly
- Trellis.Primitives.dll
ISO 3166-1 alpha-2 country code value object.
[JsonConverter(typeof(ParsableJsonConverter<CountryCode>))]
public class CountryCode : ScalarValueObject<CountryCode, string>, IComparable<ValueObject>, IEquatable<ValueObject>, IConvertible, IScalarValue<CountryCode, string>, IParsable<CountryCode>
- Inheritance
-
CountryCode
- Implements
- Inherited Members
- Extension Methods
Remarks
Validation Rules (Opinionated):
- Exactly 2 letters (ISO 3166-1 alpha-2 format)
- Normalized to uppercase
If these rules don't fit your domain (e.g., you need alpha-3 or numeric codes), create your own CountryCode value object using the ScalarValueObject<TSelf, T> base class.
Methods
Parse(string?, IFormatProvider?)
Parses a country code.
public static CountryCode Parse(string? s, IFormatProvider? provider)
Parameters
sstringproviderIFormatProvider
Returns
TryCreate(string?, string?)
Attempts to create a country code.
public static Result<CountryCode> TryCreate(string? value, string? fieldName = null)
Parameters
Returns
TryParse(string?, IFormatProvider?, out CountryCode)
Tries to parse a country code.
public static bool TryParse(string? s, IFormatProvider? provider, out CountryCode result)
Parameters
sstringproviderIFormatProviderresultCountryCode