/// <summary> /// Repeats the provided traversal until the provided condition is met /// </summary> /// <returns>The repeat.</returns> /// <param name="traversal">The sub query to repeat</param> /// <param name="condition">The condition that must be met to end the loop</param> /// <param name="type">Specifies a do-while or while-do loop</param> public Query Repeat <TOutput>(ITraversalQuery <T, TOutput> traversal, ITraversalQuery <T> condition, RepeatTypeEnum type) { if (traversal.Steps.Count < 1) { throw new ArgumentException("Provided traversal must contain at least one step"); } if (condition.Steps.Count < 1) { throw new ArgumentException("Provided condition must have at least one step"); } string until = "until(" + condition.ToString() + ")"; string repeat = "repeat(" + traversal.ToString() + ")"; switch (type) { case RepeatTypeEnum.DoWhile: Steps.Add(repeat + "." + until); break; case RepeatTypeEnum.WhileDo: Steps.Add(until + "." + repeat); break; } return(this as Query); }
/// <summary> /// Repeats the provided traversal /// </summary> /// <param name="traversal">The sub query to repeat</param> /// <param name="count">The number of times to repeat the sub query</param> public CollectionQuery <TOutput, From> Repeat <TOutput>(ITraversalQuery <T, TOutput> traversal, int count) { if (count < 1) { throw new ArgumentException("Repeat count must be greater than 0"); } if (traversal.Steps.Count < 1) { throw new ArgumentException("Provided traversal must contain at least one step"); } Steps.Add("repeat(" + traversal.ToString() + ").times(" + count.ToString() + ")"); return(new CollectionQuery <TOutput, From>(this)); }
/// <summary> /// Filters results based on a sub query /// </summary> public Query Where(ITraversalQuery <T> condition) { Steps.Add("where(" + condition.ToString() + ")"); return(this as Query); }
/// <summary> /// Returns the result of the specified traversal if it yields a result else it returns the calling element /// </summary> public Query Optional(ITraversalQuery <T, T> subquery) { Steps.Add("optional(" + subquery.ToString() + ")"); return(this as Query); }
/* * public Query Next() * { * Steps.Add("next()"); * return this as Query; * } */ /* * public Query Next(int count) * { * if (count < 1) * throw new ArgumentException("Count must be greater than zero"); * Steps.Add(string.Format("next({0})", count)); * return this as Query; * } */ /// <summary> /// Removes objects from the traversal stream when the traversal provided as an argument does not return any objects /// </summary> public Query Not(ITraversalQuery <T, T> subquery) { Steps.Add("not(" + subquery.ToString() + ")"); return(this as Query); }
/// <summary> /// Executes the provided query on each incoming item /// </summary> /// <param name="localQuery">The query to execute on each incoming item</param> public CollectionQuery <TOutput, From> Local <TOutput>(ITraversalQuery <T, TOutput> localQuery) { Steps.Add("local(" + localQuery.ToString() + ")"); return(new CollectionQuery <TOutput, From>(this)); }
/// <summary> /// Routes the current traverser to a particular traversal branch option /// </summary> /// <returns>The choose.</returns> /// <param name="condition">Condition to evaluate</param> /// <param name="TrueQuery">Path executed if the condition yields a result</param> /// <param name="FalseQuery">Path executed if the condition does not yields a result</param> public CollectionQuery <TOutput, From> Choose <TOutput>(ITraversalQuery <T> condition, ITraversalQuery <T, TOutput> TrueQuery, ITraversalQuery <T, TOutput> FalseQuery) { Steps.Add("choose(" + condition.ToString() + ", __." + TrueQuery.ToString() + ", __." + FalseQuery + ")"); return(new CollectionQuery <TOutput, From>(this)); }