Пример #1
0
        private ConditionExpression TryParseBoolOperator()
        {
            bool flag  = false;
            bool flag2 = false;
            ConditionExpression result;

            for (int i = 0; i < this.String.Length; i++)
            {
                if (this.String[i] == '"')
                {
                    flag = !flag;
                }
                else
                {
                    if (this.String[i] == '(')
                    {
                        flag2 = true;
                    }
                    else
                    {
                        if (this.String[i] == ')')
                        {
                            flag2 = false;
                        }
                        else
                        {
                            if (!flag && !flag2)
                            {
                                BoolOperatorEnum?boolOperatorEnum = BoolOperator.TryGetOperator(this.String[i]);
                                if (boolOperatorEnum.HasValue)
                                {
                                    if (i + 1 >= this.String.Length)
                                    {
                                        throw new System.Exception(string.Format("Cannot parse {0} :  Right Expression of bool operator index {1} is empty", this.String, i));
                                    }
                                    string text = this.String.Substring(0, i);
                                    if (string.IsNullOrEmpty(text))
                                    {
                                        throw new System.Exception(string.Format("Cannot parse {0} : Left Expression of bool operator index {1} is empty", this.String, i));
                                    }
                                    ConditionParser     conditionParser = new ConditionParser(text);
                                    ConditionExpression left            = conditionParser.Parse();
                                    string text2 = this.String.Substring(i + 1, this.String.Length - (i + 1));
                                    if (string.IsNullOrEmpty(text2))
                                    {
                                        throw new System.Exception(string.Format("Cannot parse {0} : Right Expression of bool operator index {1} is empty", this.String, i));
                                    }
                                    conditionParser = new ConditionParser(text2);
                                    ConditionExpression right = conditionParser.Parse();
                                    result = new BoolOperator(left, right, boolOperatorEnum.Value);
                                    return(result);
                                }
                            }
                        }
                    }
                }
            }
            result = null;
            return(result);
        }
Пример #2
0
 public override string ToString()
 {
     return(string.Format("{0}{1}{2}", this.Left, BoolOperator.GetOperatorChar(this.Operator), this.Right));
 }
Пример #3
0
        private ConditionExpression TryParseBoolOperator()
        {
            bool inQuote      = false;
            bool inParenthese = false;

            for (int i = 0; i < String.Length; i++)
            {
                if (String[i] == '\"')
                {
                    inQuote = !inQuote;
                    continue;
                }

                if (String[i] == '(')
                {
                    inParenthese = true;
                    continue;
                }

                if (String[i] == ')')
                {
                    inParenthese = false;
                    continue;
                }

                if (inQuote || inParenthese)
                {
                    continue;
                }

                var op = BoolOperator.TryGetOperator(String[i]);

                if (op != null)
                {
                    if (i + 1 >= String.Length)
                    {
                        throw new Exception(string.Format("Cannot parse {0} :  Right Expression of bool operator index {1} is empty", String, i));
                    }

                    var leftStr = String.Substring(0, i);

                    if (string.IsNullOrEmpty(leftStr))
                    {
                        throw new Exception(string.Format("Cannot parse {0} : Left Expression of bool operator index {1} is empty", String, i));
                    }

                    var parser = new ConditionParser(leftStr);
                    var left   = parser.Parse();

                    var rightStr = String.Substring(i + 1, String.Length - (i + 1));

                    if (string.IsNullOrEmpty(rightStr))
                    {
                        throw new Exception(string.Format("Cannot parse {0} : Right Expression of bool operator index {1} is empty", String, i));
                    }

                    parser = new ConditionParser(rightStr);
                    var right = parser.Parse();

                    return(new BoolOperator(left, right, op.Value));
                }
            }

            return(null);
        }