示例#1
0
        public static Currency?TryCreate(string code, CurrencyTypes types)
        {
            Require.NotNull(code, nameof(code));

            if (types.Contains(CurrencyTypes.Active))
            {
                if (Codes.TryGetValue(code, out short?minorUnits))
                {
                    return(new Currency(code, minorUnits));
                }
            }

            if (types.Contains(CurrencyTypes.UserDefined))
            {
                if (UserCodes.TryGetValue(code, out short?minorUnits))
                {
                    return(new Currency(code, minorUnits));
                }
            }

            // At last, we look for a withdrawn currency.
            if (types.Contains(CurrencyTypes.Withdrawn) && WithdrawnCodes.Contains(code))
            {
                // For withdrawn currencies, ISO 4217 does not provide any information
                // concerning the minor units. See the property HasMinorCurrency for more info.
                return(new Currency(code, UnknownMinorUnits));
            }

            return(null);
        }