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()); } }
// -------------------------------------------------------------------------------- /// <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()); } }