Example #1
0
        public static decimal CastDecimal(object sourceObj)
        {
            switch (sourceObj)
            {
            case null:
                throw new ArgumentException();

            case string stringValue:
                try {
                    return(SimpleTypeParserFunctions.ParseDecimal(stringValue));
                }
                catch (FormatException) {
                    return(default(decimal));
                }

            default:
                return(sourceObj.AsDecimal());
            }
        }
Example #2
0
        /// <summary>
        /// Casts the object to the System.Decimal
        /// </summary>
        /// <param name="sourceObj">The source object</param>
        public static decimal?CastNullableDecimal(object sourceObj)
        {
            switch (sourceObj)
            {
            case null:
                return(null);

            case string stringValue:
                try {
                    return(SimpleTypeParserFunctions.ParseDecimal(stringValue));
                }
                catch (FormatException) {
                    return(default(decimal?));
                }

            default:
                return(sourceObj.AsDecimal());
            }
        }