Exemplo n.º 1
0
        public RelationalCondition(Condition left, RelationalComparison comparison, Condition right)
        {
            left  = ConditionLogic.GetCondition(left);
            right = ConditionLogic.GetCondition(right);

            _leftCondition  = left;
            _rightCondition = right;
            _comparison     = comparison;

            Suffix = left.Suffix;
            Prefix = left.Prefix;

            left.Prefix  = "";
            left.Suffix  = "";
            right.Prefix = "";
            right.Suffix = "";

            RelationalCondition rLeft = left as RelationalCondition;

            if (rLeft != null)
            {
                RelationalComparison comp = rLeft._comparison;

                if ((comp == RelationalComparison.And || comp == RelationalComparison.Or) &&
                    (comparison == RelationalComparison.And || comparison == RelationalComparison.Or) &&
                    rLeft._comparison != comparison)
                {
                    _leftCondition = new ParenthesisCondition(rLeft);
                }
            }

            RelationalCondition rRight = right as RelationalCondition;

            if (rRight != null)
            {
                RelationalComparison comp = rRight._comparison;

                if ((comp == RelationalComparison.And || comp == RelationalComparison.Or) &&
                    (comparison == RelationalComparison.And || comparison == RelationalComparison.Or) &&
                    rRight._comparison != comparison)
                {
                    _rightCondition = new ParenthesisCondition(rRight);
                }
            }
        }
Exemplo n.º 2
0
        private static Condition _getCondition(string value)
        {
            Condition condition;

            if (value == "true" || value == "false")
            {
                condition = new BooleanCondition(value);
            }
            else
            {
                string[] values = CutBrackets(value);

                if (values.Length == 1 && values[0].StartsWith("("))
                {
                    condition = new ParenthesisCondition(values[0].Substring(1, values[0].Length - 2));
                }
                else if (values.Length == 1 && values[0].StartsWith("not(") && values[0].EndsWith(")"))
                {
                    condition = new NotCondition(values[0].Substring(4, values[0].Length - 5));
                }
                else if (values.Length == 1)
                {
                    condition = new VariableCondition(values[0]);
                }
                else if (values.Length == 3)
                {
                    //if (values[0].StartsWith("(")) {
                    //	condition = new ParenthesisCondition(values[0].Substring(1, values[0].Length - 2));
                    //}
                    condition = new RelationalCondition(values[0], values[1], values[2]);
                }
                else
                {
                    // Tougher checkup...!
                    // Give priority to && and ||
                    for (int i = 1; i < values.Length; i++)
                    {
                        if (values[i] == "&&" || values[i] == "||")
                        {
                            condition = new RelationalCondition(String.Join(" ", values.Take(i).ToArray()), values[i], "(" + String.Join(" ", values.Skip(i + 1).ToArray()) + ")");
                            return(condition);
                        }
                    }

                    // Give priority to == and ~=
                    for (int i = 1; i < values.Length; i++)
                    {
                        if (values[i] == "==" || values[i] == "~=")
                        {
                            condition = new RelationalCondition(String.Join(" ", values.Take(i).ToArray()), values[i], "(" + String.Join(" ", values.Skip(i + 1).ToArray()) + ")");
                            return(condition);
                        }
                    }

                    for (int i = 1; i < values.Length; i++)
                    {
                        if (values[i] == ">" || values[i] == ">=" || values[i] == "<" || values[i] == "<=")
                        {
                            condition = new RelationalCondition(String.Join(" ", values.Take(i).ToArray()), values[i], "(" + String.Join(" ", values.Skip(i + 1).ToArray()) + ")");
                            return(condition);
                        }
                    }

                    condition = new VariableCondition(value);
                }
            }

            return(condition);
        }