static void Main() { var value1 = 1; var value2 = 2; var value3 = new { MyValue = 3 }; var data = new DataInfo { A = 10, B = 1, C = -1 }; Expression <Func <DataInfo, decimal?> > expression = x => x.A / (x.B + x.C) + (value1 + value2) + value3.MyValue; // create a list of variables that will be used when evaluating the expression var variables = new Dictionary <Type, object>(); // add the root object variables.Add(data.GetType(), data); // find variables that are referenced in the expression var finder = new VariablesFinder(variables); finder.Visit(expression); // replace variables with ConstantExpressions var visitor = new VariableReplacer(variables); var newExpression = visitor.Visit(expression); var rulesChecker = new RulesChecker(); var checkedExpression = rulesChecker.Visit(newExpression); }
private static RulesCheckerResult GetResults(object data, Expression expression) { var visitor = new RulesChecker(data); visitor.Visit(expression); return(new RulesCheckerResult( visitor.hasConfidentielle, visitor.hasNonDiffusable, visitor.hasDivisionParZero, visitor.hasManquante)); }