Class CurrencyCode
- Namespace
- Trellis.Primitives
- Assembly
- Trellis.Primitives.dll
Represents an ISO 4217 currency code as a value object.
[JsonConverter(typeof(ParsableJsonConverter<CurrencyCode>))]
public class CurrencyCode : ScalarValueObject<CurrencyCode, string>, IComparable<ValueObject>, IEquatable<ValueObject>, IConvertible, IScalarValue<CurrencyCode, string>, IParsable<CurrencyCode>
- Inheritance
-
CurrencyCode
- Implements
- Inherited Members
- Extension Methods
Remarks
Validation Rules (Opinionated):
Valid codes are three alphabetic characters (e.g., USD, EUR, GBP). The stored value is uppercase.
If these rules don't fit your domain (e.g., cryptocurrency codes like BTC, ETH), create your own CurrencyCode value object using the ScalarValueObject<TSelf, T> base class.
Methods
Parse(string?, IFormatProvider?)
Parses a currency code.
public static CurrencyCode Parse(string? s, IFormatProvider? provider)
Parameters
sstringproviderIFormatProvider
Returns
TryCreate(string?, string?)
Attempts to create a currency code from a 3-letter ISO 4217 code.
public static Result<CurrencyCode> TryCreate(string? value, string? fieldName = null)
Parameters
Returns
TryParse(string?, IFormatProvider?, out CurrencyCode)
Tries to parse a currency code.
public static bool TryParse(string? s, IFormatProvider? provider, out CurrencyCode result)
Parameters
sstringproviderIFormatProviderresultCurrencyCode