Пример #1
0
            /// <summary>
            /// Create a SimpleExpression or a BooleanExpression based on the string that this method receive
            /// </summary>
            /// <param name="SimpleExpression"></param>
            /// <returns></returns>
            public static BooleanOperand Create(string ExpressionToEvaluate)
            {
                Regex re;
                Match m;

                re = new Regex(@"(?<exp1>.*)\s*(?<op>[&][&]|[|][|])\s*(?<exp2>.*)\s*");
                m  = re.Match(ExpressionToEvaluate);
                if (m.Success)                  // complex expression ==> a=1 && b>4
                {
                    // exp2 is a simple expression for sure
                    BooleanOperand      exp2     = BooleanOperand.Create(m.Groups["exp2"].Value);
                    BooleanOperatorType Operator = BooleanExpression.GetBooleanOperator(m.Groups["op"].Value);
                    BooleanOperand      exp1     = BooleanOperand.Create(m.Groups["exp1"].Value);

                    BooleanExpression be = new BooleanExpression(exp1, Operator, exp2);

                    return(be);
                }

                // At this point it's a simple expression
                re = new Regex(@"(?:(?<left>\w+)\s*(?<op>[=]|[>]|[<]|[<][=]|[>][=])\s*(?<right>[\x22]?\w+[\x22]?))");
                m  = re.Match(ExpressionToEvaluate);
                if (!m.Success)
                {
                    throw new Exception("Invalid SimpleExpression: " + ExpressionToEvaluate);
                }

                string             Property           = m.Groups["left"].Value;
                string             Value              = m.Groups["right"].Value;
                SimpleOperatorType ExpressionOperator = SimpleExpression.GetExpressionOperator(m.Groups["op"].Value);

                SimpleExpression simple = new SimpleExpression(Property, ExpressionOperator, Value);

                return(simple);
            }