public static short CastInt16(object sourceObj) { switch (sourceObj) { case null: throw new ArgumentException(); case string stringValue: try { return(SimpleTypeParserFunctions.ParseInt16(stringValue)); } catch (FormatException) { return(default(short)); } default: return(sourceObj.AsInt16()); } }
// -------------------------------------------------------------------------------- /// <summary> /// Casts the object to the System.Int16 /// </summary> /// <param name="sourceObj">The source object</param> public static short?CastNullableInt16(object sourceObj) { switch (sourceObj) { case null: return(null); case string stringValue: try { return(SimpleTypeParserFunctions.ParseInt16(stringValue)); } catch (FormatException) { return(default(short?)); } default: return(sourceObj.AsInt16()); } }