} //to avoid an XAML annoying warning: "No constructor for type 'xyz' has 0 parameters." Somehow the inherited one doesn't do the trick!?! I guess it's a reflection buggy. // ReSharper restore EmptyConstructor public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null || value == DBNull.Value) { return(Visibility.Visible); } return(StringEvaluator.EvalToBool(parameter.ToString().Replace("?", value.ToString())) ? Visibility.Visible : Visibility.Collapsed); }
private static double EvaluateSuccess(string input) { var evaluator = new StringEvaluator(); var result = evaluator.Evaluate(input); result.IsSuccessful.Should().BeTrue(); return(result.Result); }
} //to avoid an XAML annoying warning: "No constructor for type 'xyz' has 0 parameters." Somehow the inherited one doesn't do the trick!?! I guess it's a reflection buggy. // ReSharper restore EmptyConstructor public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var expression = parameter.ToString().Replace("?", (value ?? "").ToString()); if (VariableReplacement != null) { VariableReplacement(ref expression); } return(StringEvaluator.EvalToBool(expression.ToLower())); //nugget: }
public static T Evaluate <T>(RPNExpression expression) { try { var context = new RPNContext(expression); while (context.CanMove) { context.MoveNext(); if (DefaultEvaluator.Evaluate(context)) { continue; } if (BasicEvaluator.Evaluate(context)) { continue; } if (MathEvaluator.Evaluate(context)) { continue; } if (LogicEvaluator.Evaluate(context)) { continue; } if (StringEvaluator.Evaluate(context)) { continue; } if (RegexEvaluator.Evaluate(context)) { continue; } if (DateTimeEvaluator.Evaluate(context)) { continue; } if (ControlEvaluator.Evaluate <T>(context)) { continue; } context.Stack.Push(context.Current); } return(context.GetResult <T>()); } catch (RPNException) { throw; } catch { throw new ParsingException(expression.Expression); } }
public void Variable_not_found() { var sut = new StringEvaluator(); var dict = new Dictionary <string, object>(); var actual = sut.Evaluate("This will {fail}", dict); var expected = Either.Error <RuntimeErrors, string>(new RuntimeErrors(new ReferenceToUnsetVariable("fail"))); actual.Should().BeEquivalentTo(expected, options => options .ComparingByMembers(typeof(Either <,>)) .ComparingByMembers(typeof(Option <RuntimeErrors>))); }
public void All_variables_should_be_found() { var sut = new StringEvaluator(); var dict = new Dictionary <string, object> { { "replaced", "mate" }, { "replaced_between_braces", "boy!" }, { "non_replaced", "will not appear on resulting string" }, }; var actual = sut.Evaluate("Hello {replaced}, {{non_replaced}}, {{{replaced_between_braces}}}", dict); var expected = Either.Success <RuntimeErrors, string>("Hello mate, {non_replaced}, {boy!}"); actual.Should().BeEquivalentTo(expected); }
/// <summary> /// /// </summary> /// <param name="drv"></param> /// <param name="isValid"></param> /// <param name="fieldName">to reference another field to be invalidated as well, comma delimit with no spaces (yeah i know it's hacky)</param> /// <param name="doValidation"> </param> /// <param name="expression"></param> /// <param name="message"></param> /// <returns></returns> protected bool ValidateGeneric(DataRowView drv, ref bool isValid, string fieldName, bool doValidation = true, string expression = "'?' != ''", string message = "Required") { //if (!drv.IsDirty()) return (true); string[] flds = fieldName.Split(','); if (flds.Length == 2) { fieldName = flds[0]; } bool isvalid = true; if (doValidation) { isvalid = StringEvaluator.EvalToBool(expression.Replace("?", drv[fieldName].ToString())); } isValid = isValid && isvalid; //if error, set error and notify UI, otherwise clear any existing errors if (!isvalid) { if (flds.Length == 2) { drv.SetColumnError(flds[1], message); } drv.SetColumnError(fieldName, message); //nugget: setting errors on ADO.Net DataRowView fields which propogate all the way back up to little red boxes & tooltips on the corresponding UI widgets } else { if (flds.Length == 2) { drv.ClearColumnError(flds[1]); } drv.ClearColumnError(fieldName); } return(isvalid); }
} //to avoid an annoying warning from XAML designer: "No constructor for type 'xyz' has 0 parameters." Somehow the inherited one doesn't do the trick!?! I guess it's a reflection buggy. // ReSharper restore EmptyConstructor public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return(StringEvaluator.EvalToString(parameter.ToString().Replace("?", value.ToString()))); }