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); }
public Condition <T> InCondition(string field, EListOperator oper) { Contract.Requires(!String.IsNullOrWhiteSpace(field)); Contract.Requires(oper == EListOperator.In || oper == EListOperator.NotIn); CheckRoot(); ListCondition <T> condition = new ListCondition <T>(); ClauseVariable var = new ClauseVariable(); var.Name = field; condition.LeftElement = var; condition.Operator = oper; AddCondition(condition); return(condition); }
private Condition <T> AddClause(ClauseElement clause) { Condition <T> parent = stack.Peek(); if (parent.GetType() == typeof(ListCondition <T>)) { ListCondition <T> list = (ListCondition <T>)parent; if (list.IsClosed()) { throw new QueryException(String.Format("Invalid Stack State: List condition is already closed. [type={0}]", list.GetType().FullName)); } if (clause.GetType() != typeof(ClauseValue)) { throw new QueryException(String.Format("Invalid Clause: Expected Value clause. [type={0}]", clause.GetType().FullName)); } list.AddValue((ClauseValue)clause); return(list); } else if (parent.GetType() == typeof(BasicCondition <T>)) { BasicCondition <T> condition = (BasicCondition <T>)parent; if (condition.IsClosed()) { throw new QueryException(String.Format("Invalid Stack State: List condition is already closed. [type={0}]", condition.GetType().FullName)); } if (condition.LeftElement == null) { condition.LeftElement = clause; } else { condition.RightElement = clause; } return(condition); } throw new QueryException(String.Format("Invalid Stack State: Cannot add clause. [type={0}]", parent.GetType().FullName)); }