/// <summary> /// Creates asynchronous loop expression. /// </summary> /// <param name="collection">The collection to iterate through.</param> /// <param name="cancellationToken">The expression of type <see cref="CancellationToken"/>.</param> /// <param name="configureAwait"><see langword="true"/> to call <see cref="ValueTask.ConfigureAwait(bool)"/> with <see langword="false"/> argument when awaiting <see cref="IAsyncEnumerator{T}.MoveNextAsync"/> method.</param> /// <param name="body">A delegate that is used to construct the body of the loop.</param> /// <returns>The expression instance.</returns> /// <seealso cref="IAsyncEnumerable{T}"/> /// <seealso cref="IsAwaitable"/> public static ForEachExpression Create(Expression collection, Expression cancellationToken, bool configureAwait, Statement body) { var result = new ForEachExpression(collection, cancellationToken, configureAwait); result.Body = body(result.Element, result.ContinueLabel, result.BreakLabel); return(result); }
/// <summary> /// Creates a new loop expression. /// </summary> /// <param name="collection">The collection to iterate through.</param> /// <param name="body">A delegate that is used to construct the body of the loop.</param> /// <returns>The expression instance.</returns> public static ForEachExpression Create(Expression collection, Statement body) { var result = new ForEachExpression(collection); result.Body = body(result.Element, result.ContinueLabel, result.BreakLabel); return(result); }