public static byte CastByte(object sourceObj) { switch (sourceObj) { case null: throw new ArgumentException(); case string stringValue: try { return(SimpleTypeParserFunctions.ParseByte(stringValue)); } catch (FormatException) { return(default(byte)); } default: return(sourceObj.AsByte()); } }
/// <summary> /// Casts the object to the System.Byte /// </summary> /// <param name="sourceObj">The source object</param> public static byte?CastNullableByte(object sourceObj) { switch (sourceObj) { case null: return(null); case string stringValue: try { return(SimpleTypeParserFunctions.ParseByte(stringValue)); } catch (FormatException) { return(default(byte?)); } default: return(sourceObj.AsByte()); } }