예제 #1
0
        protected override string _getStringValue()
        {
            NotCondition nC = Condition as NotCondition;

            if (nC != null)
            {
                if (!IsReversed && !nC.IsReversed)
                {
                    return(Condition);
                }
            }

            if (IsReversed && !(Condition is RelationalCondition))
            {
                return(Condition);
            }

            if (!IsReversed)
            {
                if (Condition is RelationalCondition || Condition is BooleanCondition)
                {
                    return(Condition.Reverse());
                }
            }

            return(IsReversed ? "(" + Condition + ")" : "not(" + Condition + ")");
        }
예제 #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);
        }