// Pixels public static Parsed <Pixels> TryParsePixels(this string str) { double value; if (Double.TryParse(str.StripSuffix("px"), out value)) { return(Parsed.Success(new Pixels(value), str)); } return(Parsed.Failure <Pixels>(str)); }
public static Parsed <int> TryParseInt(string str) { int value; if (int.TryParse(str, out value)) { return(Parsed.Success(value, str)); } return(Parsed.Failure <int>(str)); }
public static Parsed <double> TryParseDouble(string str) { double value; if (double.TryParse(str, out value)) { return(Parsed.Success(value, str)); } return(Parsed.Failure <double>(str)); }
public static Parsed <float> TryParseFloat(string str) { float value; if (float.TryParse(str, out value)) { return(Parsed.Success(value, str)); } return(Parsed.Failure <float>(str)); }
static Parsed <bool> TryParseBoolean(string str) { bool value; if (Boolean.TryParse(str, out value)) { return(Parsed.Success(value, str)); } return(Parsed.Failure <bool>(str)); }
static Parsed <TimeSpan> TryParseTimeSpan(string str) { double value; if (double.TryParse(str.StripSuffix("s"), out value)) { return(Parsed.Success(TimeSpan.FromSeconds(value), str)); } return(Parsed.Failure <TimeSpan>(str)); }
static Parsed <T> TryParseEnum <T>(string str) where T : struct { T value; if (Enum.TryParse(str, out value) && Enum.IsDefined(typeof(T), value)) { return(Parsed.Success(value, str)); } return(Parsed.Failure <T>(str)); }
// Percentages public static Parsed <Percentages> TryParsePercentages(this string str) { if (!str.EndsWith("%")) { return(ScalarParser.TryParseDouble(str).Select(d => new Percentages(d))); } double value; if (double.TryParse(str.StripSuffix("%"), out value)) { return(Parsed.Success(new Percentages(value), str)); } return(Parsed.Failure <Percentages>(str)); }