private static string GetChainedExpression(CAMLChainedExpression chainedExpression) { var statementList = chainedExpression.Expressions.Select(GetSingleExpression).ToList(); var statementStack = new Stack <string>(); foreach (var statement in statementList) { statementStack.Push(statement); } // Recursively build up query Func <Stack <string>, string> process = null; process = stack => { // Pop the first two statements, combine then with the condition operator. // If only one item left, entire statement chain has been processed, so retur the result if (stack.Count == 0) { return(string.Empty); } if (stack.Count == 1) { return(stack.Pop()); } var statement1 = stack.Pop(); var statement2 = stack.Pop(); var expr = String.Format(@"<{0}>{1}{2}</{0}>", chainedExpression.Condition, statement1, statement2); stack.Push(expr); return(process(stack)); }; return(process(statementStack)); }
public void CAMLBuilder_Chained_3_Expression() { var expression = GetSinglExpression() as CAMLExpression; var chain = new CAMLChainedExpression { Condition = CAMLCondition.And, Expressions = new List<CAMLExpression> { expression, expression, expression } }; var builder = new CAMLBuilder(chain); var checkString = GetThreeChainString(chain); Assert.IsTrue(builder.ToString().Equals(checkString)); }
public void CAMLBuilder_Chained_2_Expression() { var expression = GetSinglExpression() as CAMLExpression; var chain = new CAMLChainedExpression { Condition = CAMLCondition.And, Expressions = new List<CAMLExpression> { expression, expression } }; var builder = new CAMLBuilder(chain); var checkString = String.Format(@"<Where><{0}>{1}{1}</{0}></Where>", chain.Condition, GetSingleString(expression)); Assert.IsTrue(builder.ToString().Equals(checkString)); }
private static string GetChainedExpression(CAMLChainedExpression chainedExpression) { var statementList = chainedExpression.Expressions.Select(GetSingleExpression).ToList(); var statementStack = new Stack<string>(); foreach (var statement in statementList) statementStack.Push(statement); // Recursively build up query Func<Stack<string>, string> process = null; process = stack => { // Pop the first two statements, combine then with the condition operator. // If only one item left, entire statement chain has been processed, so retur the result if (stack.Count == 0) return string.Empty; if (stack.Count == 1) return stack.Pop(); var statement1 = stack.Pop(); var statement2 = stack.Pop(); var expr = String.Format(@"<{0}>{1}{2}</{0}>", chainedExpression.Condition, statement1, statement2); stack.Push(expr); return process(stack); }; return process(statementStack); }
private string GetThreeChainString(CAMLChainedExpression chain) { var expression = chain.Expressions[0]; return String.Format(@"<Where><{0}><{0}>{1}{1}</{0}>{1}</{0}></Where>", chain.Condition, GetSingleString(expression)); }