public void Action(Untrusted <string> input) { // only way of getting the value is through a ValidatorBase implementation. var value = new SanitizeStringValidator().Validate(input); DoStuff(value); }
public static Try <string, double> Add( Untrusted <string> fst, Untrusted <string> snd ) => from f in ParseToDouble(fst) from s in ParseToDouble(snd) select f + s;
public static Try <string, double> Add(Untrusted <string> fst, Untrusted <string> snd) { Func <double, double, double> add = (a, b) => a + b; return(Try <string, Func <double, double, double> > .Of(add) .Apply(ParseToDouble(fst)) // Try<FailedToParseDoubleException, Func<double, double>> .Apply(ParseToDouble(snd))); // Try<FailedToParseDoubleException, double> }
public static Try <string, double> Add(Untrusted <string> fst, Untrusted <string> snd) => ParseToDouble(fst).Match( success: f => ParseToDouble(snd).Match <Try <string, double> >( success: s => f + s, failure: e => e ), failure: e => e );
public bool Untrusted_Unwraps_Value_In_Maybe_Based_On_Given_Validation(NonNull <object> x, Maybe <NonNull <object> > m) { return(Untrusted <object> .Wrap(x.Get) .Unwrap(_ => m.Select(o => o.Get)) .Equals(Maybe <object> .Nothing) .Equals(m.Equals(Maybe <NonNull <object> > .Nothing))); }
private static Option <double> ParseToDouble(Untrusted <string> source) { var result = 0d; return(source.Validate( s => double.TryParse(s, out result), onSuccess: _ => result )); }
public T Validate(Untrusted <T> untrusted) { if (!InnerValidate(untrusted.Value)) { throw new ValidationException(); } return(untrusted.Value); }
private static Try <string, double> ParseToDouble(Untrusted <string> source) { var result = 0d; return(source.Validate( s => double.TryParse(s, out result), failure: s => $"Failed to parse '{s}' to double", success: _ => result )); }
public bool Untrusted_Unwraps_Value_In_Result_Based_On_Given_Validation( NonNull <object> x, Result <NonNull <object>, NonNull <object> > m) { return(Untrusted <object> .Wrap(x) .Unwrap(_ => m) .GetOk() .Equals(Maybe <NonNull <object> > .Nothing) .Equals(m.GetOk().Equals(Maybe <NonNull <object> > .Nothing))); }
public static Try <string, double> Add( Untrusted <string> fst, Untrusted <string> snd ) => ParseToDouble(fst).Bind(f => ParseToDouble(snd).Map(s => f + s));
public static Option <double> Add(Untrusted <string> fst, Untrusted <string> snd) => Option.Of <Func <double, double, double> >((a, b) => a + b) .Apply(ParseToDouble(fst)) // Option<Func<double, double>> .Apply(ParseToDouble(snd)); // Option<double>