示例#1
0
        public static ushort CastUInt16(object sourceObj)
        {
            switch (sourceObj)
            {
            case null:
                throw new ArgumentException();

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

            default:
                return(sourceObj.AsUInt16());
            }
        }
示例#2
0
        // --------------------------------------------------------------------------------

        /// <summary>
        /// Casts the object to the System.UInt16
        /// </summary>
        /// <param name="sourceObj">The source object</param>
        public static ushort?CastNullableUInt16(object sourceObj)
        {
            switch (sourceObj)
            {
            case null:
                return(null);

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

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