Example #1
0
 /// <summary>
 /// Creates a single instance of this object.
 /// </summary>
 /// <returns></returns>
 public static RomanNumeralsBase Instance()
 {
     lock (m_locker)
     {
         if (m_currentInstance == null)
         {
             m_currentInstance = new RomanNumeralsBase();
         }
     }
     return(m_currentInstance);
 }
Example #2
0
        /// <summary>
        /// Converts the value of the specified RomanNumeral to System.Decimal
        /// </summary>
        /// <returns></returns>
        public Decimal ToDecimal()
        {
            //filed to return after we populate it
            Decimal           result    = 0;
            RomanNumeralsBase romanBase = RomanNumeralsBase.Instance();

            //We need to loop all base roman numerals
            foreach (KeyValuePair <string, short> baseRomanNumeral in romanBase.Numerals)
            {
                //Each time the current Base Roman Numeral is found we need to act on it
                while (m_romanNumeralValue.IndexOf(baseRomanNumeral.Key) == 0)
                {
                    //Add current value
                    result += baseRomanNumeral.Value;

                    //Remove current value so we don't double count it.
                    m_romanNumeralValue = m_romanNumeralValue.Substring(baseRomanNumeral.Key.Length);
                }
            }

            return(result);
        }