public static IMaybe <T> ParseAsMaybe <T>(this string value) where T : struct { T result; return(TryParseHelper <T> .TryParse(value, out result) ? result.ToMaybe() : Maybe <T> .None); }
/// <summary> /// /// </summary> /// <param name="elem"></param> /// <param name="val"></param> /// <returns></returns> public static bool TryParseValue <T>(this XElement elem, out T val) where T : struct { bool isSuccessful = true; if (TryParseHelper <T> .TryParse(elem.Value, out val) == false) { val = default; isSuccessful = false; } return(isSuccessful); }
/// <summary> /// /// </summary> /// <param name="elem"></param> /// <param name="val"></param> /// <returns></returns> public static bool TryParseValue <T>(this XElement elem, out T?val) where T : struct { bool isSuccessful = true; if (elem == null || TryParseHelper <T> .TryParse(elem.Value, out T returnValue) == false) { val = null; isSuccessful = false; } else { val = returnValue; } return(isSuccessful); }