Example #1
0
        public Condition <T> Close()
        {
            Condition <T> condition = stack.Pop();

            if (condition.GetType() == typeof(ConditionGroup <T>))
            {
                ConditionGroup <T> group = (ConditionGroup <T>)condition;
                group.Validate();
                group.Close();
            }
            else if (condition.GetType() == typeof(ListCondition <T>))
            {
                ListCondition <T> list = (ListCondition <T>)condition;
                list.Validate();
                list.Close();
            }
            else
            {
                if (!condition.IsClosed())
                {
                    throw new QueryException(String.Format("Invalid Stack State: Condition is not closed. [type={0}]", condition.GetType().FullName));
                }
            }
            return(condition);
        }
Example #2
0
        public Condition <T> Group()
        {
            CheckRoot();
            ConditionGroup <T> group = new ConditionGroup <T>();

            AddCondition(group);
            return(group);
        }
Example #3
0
 private void CheckRoot()
 {
     if (root == null)
     {
         root = new ConditionGroup <T>();
     }
     stack.Push(root);
 }
Example #4
0
        private void AddCondition(Condition <T> condition)
        {
            Condition <T> parent = stack.Peek();

            if (parent.GetType() == typeof(ConditionGroup <T>))
            {
                ConditionGroup <T> group = (ConditionGroup <T>)parent;
                if (group.IsClosed())
                {
                    throw new QueryException(String.Format("Invalid Stack State: Group condition is already closed. [type={0}]", group.GetType().FullName));
                }
                group.Add(condition);
            }
            else if (parent.GetType() == typeof(AndCondition <T>))
            {
                AndCondition <T> and = (AndCondition <T>)parent;
                if (and.IsClosed())
                {
                    throw new QueryException(String.Format("Invalid Stack State: And condition is already closed. [type={0}]", and.GetType().FullName));
                }
                and.Add(condition);
            }
            else if (parent.GetType() == typeof(AndCondition <T>))
            {
                AndCondition <T> and = (AndCondition <T>)parent;
                if (and.IsClosed())
                {
                    throw new QueryException(String.Format("Invalid Stack State: And condition is already closed. [type={0}]", and.GetType().FullName));
                }
                and.Add(condition);
            }
            else if (parent.GetType() == typeof(OrCondition <T>))
            {
                OrCondition <T> or = (OrCondition <T>)parent;
                if (or.IsClosed())
                {
                    throw new QueryException(String.Format("Invalid Stack State: Or condition is already closed. [type={0}]", or.GetType().FullName));
                }
                or.Add(condition);
            }
            stack.Push(condition);
        }