public static float CastSingle(object sourceObj) { switch (sourceObj) { case null: throw new ArgumentException(); case string stringValue: try { return(SimpleTypeParserFunctions.ParseFloat(stringValue)); } catch (FormatException) { return(default(float)); } default: return(sourceObj.AsFloat()); } }
/// <summary> /// Casts the object to the System.Single /// </summary> /// <param name="sourceObj">The source object</param> public static float?CastNullableSingle(object sourceObj) { switch (sourceObj) { case null: return(null); case string stringValue: try { return(SimpleTypeParserFunctions.ParseFloat(stringValue)); } catch (FormatException) { return(default(float?)); } default: return(sourceObj.AsFloat()); } }