| | 1 | | using Domain.Common; |
| | 2 | |
|
| | 3 | | namespace Domain.Currencies |
| | 4 | | { |
| | 5 | | public record CurrencyCode |
| | 6 | | { |
| 24 | 7 | | protected internal CurrencyCode() { } |
| 1 | 8 | | internal static Error InvalidCodeError = new Error(ErrorCode.BadInput, "The currency code is invalid"); |
| | 9 | |
|
| 1 | 10 | | public static readonly CurrencyCode Usd = new("USD", "United States Dollar"); |
| 1 | 11 | | public static readonly CurrencyCode Eur = new("EUR", "Euro"); |
| 1 | 12 | | public static readonly CurrencyCode Aud = new("AUD", "Australian Dollar"); |
| 1 | 13 | | public static readonly CurrencyCode Bgn = new("BGN", "Bulgarian Lev"); |
| 1 | 14 | | public static readonly CurrencyCode Brl = new("BRL", "Brazilian Real"); |
| 1 | 15 | | public static readonly CurrencyCode Cad = new("CAD", "Canadian Dollar"); |
| 1 | 16 | | public static readonly CurrencyCode Chf = new("CHF", "Swiss Franc"); |
| 1 | 17 | | public static readonly CurrencyCode Cny = new("CNY", "Chinese Renminbi Yuan"); |
| 1 | 18 | | public static readonly CurrencyCode Czk = new("CZK", "Czech Koruna"); |
| 1 | 19 | | public static readonly CurrencyCode Dkk = new("DKK", "Danish Krone"); |
| 1 | 20 | | public static readonly CurrencyCode Gbp = new("GBP", "British Pound"); |
| 1 | 21 | | public static readonly CurrencyCode Hkd = new("HKD", "Hong Kong Dollar"); |
| 1 | 22 | | public static readonly CurrencyCode Huf = new("HUF", "Hungarian Forint"); |
| 1 | 23 | | public static readonly CurrencyCode Idr = new("IDR", "Indonesian Rupiah"); |
| 1 | 24 | | public static readonly CurrencyCode Ils = new("ILS", "Israeli New Sheqel"); |
| 1 | 25 | | public static readonly CurrencyCode Inr = new("INR", "Indian Rupee"); |
| 1 | 26 | | public static readonly CurrencyCode Isk = new("ISK", "Icelandic Króna"); |
| 1 | 27 | | public static readonly CurrencyCode Jpy = new("JPY", "Japanese Yen"); |
| 1 | 28 | | public static readonly CurrencyCode Krw = new("KRW", "South Korean Won"); |
| 1 | 29 | | public static readonly CurrencyCode Mxn = new("MXN", "Mexican Peso"); |
| 1 | 30 | | public static readonly CurrencyCode Myr = new("MYR", "Malaysian Ringgit"); |
| 1 | 31 | | public static readonly CurrencyCode Nok = new("NOK", "Norwegian Krone"); |
| 1 | 32 | | public static readonly CurrencyCode Nzd = new("NZD", "New Zealand Dollar"); |
| 1 | 33 | | public static readonly CurrencyCode Php = new("PHP", "Philippine Peso"); |
| 1 | 34 | | public static readonly CurrencyCode Pln = new("PLN", "Polish Złoty"); |
| 1 | 35 | | public static readonly CurrencyCode Ron = new("RON", "Romanian Leu"); |
| 1 | 36 | | public static readonly CurrencyCode Sek = new("SEK", "Swedish Krona"); |
| 1 | 37 | | public static readonly CurrencyCode Sgd = new("SGD", "Singapore Dollar"); |
| 1 | 38 | | public static readonly CurrencyCode Thb = new("THB", "Thai Baht"); |
| 1 | 39 | | public static readonly CurrencyCode Try = new("TRY", "Turkish Lira"); |
| 1 | 40 | | public static readonly CurrencyCode Zar = new("ZAR", "South African Rand"); |
| 1 | 41 | | public static readonly CurrencyCode Hrk = new("HRK", "Croatian Kuna"); |
| 1 | 42 | | public static readonly CurrencyCode Rub = new("RUB", "Russian Ruble"); |
| | 43 | |
|
| 33 | 44 | | private CurrencyCode(string code, string description) |
| 33 | 45 | | { |
| 33 | 46 | | Value = code; |
| 33 | 47 | | Description = description; |
| 33 | 48 | | } |
| | 49 | |
|
| 5038 | 50 | | public string Value { get; init; } |
| 96 | 51 | | public string Description { get; init; } |
| | 52 | |
|
| | 53 | | public static Result<CurrencyCode> FromCode(string code) |
| 466 | 54 | | { |
| 4359 | 55 | | return All.FirstOrDefault(c => c.Value == code) ?? |
| 466 | 56 | | Result.Failure<CurrencyCode>(InvalidCodeError); |
| 466 | 57 | | } |
| | 58 | |
|
| 1 | 59 | | public static readonly IReadOnlyCollection<CurrencyCode> All = new[] |
| 1 | 60 | | { |
| 1 | 61 | | Usd, |
| 1 | 62 | | Eur, |
| 1 | 63 | | Aud, |
| 1 | 64 | | Bgn, |
| 1 | 65 | | Brl, |
| 1 | 66 | | Cad, |
| 1 | 67 | | Chf, |
| 1 | 68 | | Cny, |
| 1 | 69 | | Czk, |
| 1 | 70 | | Dkk, |
| 1 | 71 | | Gbp, |
| 1 | 72 | | Hkd, |
| 1 | 73 | | Huf, |
| 1 | 74 | | Idr, |
| 1 | 75 | | Ils, |
| 1 | 76 | | Inr, |
| 1 | 77 | | Isk, |
| 1 | 78 | | Jpy, |
| 1 | 79 | | Krw, |
| 1 | 80 | | Mxn, |
| 1 | 81 | | Myr, |
| 1 | 82 | | Nok, |
| 1 | 83 | | Nzd, |
| 1 | 84 | | Php, |
| 1 | 85 | | Pln, |
| 1 | 86 | | Ron, |
| 1 | 87 | | Sek, |
| 1 | 88 | | Sgd, |
| 1 | 89 | | Thb, |
| 1 | 90 | | Try, |
| 1 | 91 | | Zar, |
| 1 | 92 | | Hrk, |
| 1 | 93 | | Rub |
| 1 | 94 | | }; |
| | 95 | | } |
| | 96 | | } |