Ejemplo n.º 1
0
        public static int CastInt32(object sourceObj)
        {
            switch (sourceObj)
            {
            case null:
                throw new ArgumentException();

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

            default:
                return(sourceObj.AsInt32());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Casts the object to the System.Int32
        /// </summary>
        /// <param name="sourceObj">The source object</param>
        public static int?CastNullableInt32(object sourceObj)
        {
            switch (sourceObj)
            {
            case null:
                return(null);

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

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