/// <summary>
        /// Trys to parse config word and return coins info for the constructor
        /// {coin byre code}={coin value}={coin name};
        ///                 ^ splitter   ^ splitter  ^entry splitter
        /// </summary>
        /// <param name="word">config word</param>
        /// <param name="coins">out dictionary for parsed word, null if parsing fails</param>
        /// <returns>true for success, otherwise - false</returns>
        public static bool TryParseConfigWord(string word, out Dictionary <byte, CoinTypeInfo> coins)
        {
            try
            {
                var coinWords = word.Split(';');
                coins = new Dictionary <byte, CoinTypeInfo>(coinWords.Length);
                foreach (var coinWord in coinWords)
                {
                    if (string.IsNullOrEmpty(coinWord))
                    {
                        continue;
                    }
                    var values = coinWord.Split('=');
                    var code   = Byte.Parse(values[0]);
                    var value  = decimal.Parse(values[1], NumberStyles.Currency);
                    var name   = values.Length >= 3 ? values[2] : values[1];
                    coins[code] = new CoinTypeInfo(name, value);
                }
            }
            catch (Exception)
            {
                coins = null;
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Trys to parse config word and return coins info for the constructor
        /// {coin byre code}={coin value}={coin name};
        ///                 ^ splitter   ^ splitter  ^entry splitter
        /// </summary>
        /// <param name="word">config word</param>
        /// <param name="coins">out dictionary for parsed word, null if parsing fails</param>
        /// <returns>true for success, otherwise - false</returns>
        public static bool TryParseConfigWord(string word, out Dictionary<byte, CoinTypeInfo> coins)
        {
            try
            {
                var coinWords = word.Split(';');
                coins = new Dictionary<byte, CoinTypeInfo>(coinWords.Length);
                foreach (var coinWord in coinWords)
                {
                    if (string.IsNullOrEmpty(coinWord))
                        continue;
                    var values = coinWord.Split('=');
                    var code = Byte.Parse(values[0]);
                    var value = decimal.Parse(values[1], NumberStyles.Currency);
                    var name = values.Length >= 3 ? values[2] : values[1];
                    coins[code] = new CoinTypeInfo(name, value);
                }
            }
            catch (Exception)
            {
                coins = null;
                return false;
            }

            return true;
        }