Ejemplo n.º 1
0
        /// <summary>
        /// Trys to parse config word and return coins info for the constructor
        /// {note byre code}={note value}={note name};
        ///                 ^ splitter   ^ splitter  ^entry splitter
        /// </summary>
        /// <param name="word">config word</param>
        /// <param name="notes">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, BillTypeInfo> notes)
        {
            try
            {
                var coinWords = word.Split(';');
                notes = new Dictionary <byte, BillTypeInfo>(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];
                    notes[code] = new BillTypeInfo(name, value);
                }
            }
            catch (Exception)
            {
                notes = null;
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Trys to parse config word and return coins info for the constructor
        /// {note byre code}={note value}={note 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, BillTypeInfo> notes)
        {
            try
            {
                var coinWords = word.Split(';');
                notes = new Dictionary<byte, BillTypeInfo>(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];
                    notes[code] = new BillTypeInfo(name, value);
                }
            }
            catch (Exception)
            {
                notes = null;
                return false;
            }

            return true;
        }