Exemple #1
0
        public Func <Document, bool> CompileRule(EnabledRule r)
        {
            var        paramDoc = Expression.Parameter(typeof(Document));
            Expression expr     = BuildExpr(r, paramDoc);

            return(Expression.Lambda <Func <Document, bool> >(expr, paramDoc).Compile());
        }
Exemple #2
0
        Expression BuildExpr(EnabledRule r, ParameterExpression paramDoc)
        {
            var            left = MemberExpression.Property(paramDoc, r.StatusName);
            ExpressionType tBinary;

            // is the operator a known .NET operator?
            if (ExpressionType.TryParse(r.StatusOperator, out tBinary))
            {
                var right = Expression.Constant(r.StatusValue);
                // use a binary operation, e.g. 'Equal' -> 'doc.Status == 1'
                var exp = Expression.MakeBinary(tBinary, left, right);

                return(exp);
            }
            throw new Exception("Неизвестное выражение");
        }