RazorDocs Search

Extensions

Type

EnumerableExtensions

Provides extension methods for IEnumerable{T} to perform parallel operations.

Method

ParallelSelectAsync

2 overloads
Task<IEnumerable<TResult>> ParallelSelectAsync<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, CancellationToken, Task<TResult>> body, int maxDegreeOfParallelism, CancellationToken cancellationToken = default)

Projects each element of a sequence into a new form with bounded concurrency and preserves the input order of results.

Parameters

  • sourceThe sequence of input items.
  • bodyAn asynchronous transform that receives an input item and a cancellation token and produces a result.
  • maxDegreeOfParallelismThe maximum number of concurrent invocations of body; must be greater than zero.
  • cancellationTokenA token to observe while waiting for tasks to complete.

Returns

An IEnumerable{T} of results in the same order as the input sequence.

Exceptions

  • ArgumentNullExceptionThrown when source or body is null.
  • ArgumentOutOfRangeExceptionThrown when maxDegreeOfParallelism is less than or equal to zero.
  • OperationCanceledExceptionThe operation was canceled via cancellationToken.

Remarks

Exceptions thrown by the body function propagate to the returned task.

IAsyncEnumerable<TResult> ParallelSelectAsync<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, Task<TResult>> body, int maxDegreeOfParallelism, CancellationToken cancellationToken = default)

Produces an async sequence of results projected from each element of source, yielding results in the original input order while limiting concurrent selector executions.

Parameters

  • sourceThe input sequence to project.
  • bodyA selector that produces a Task{TResult} for an input element; this selector does not receive or observe the supplied cancellationToken.
  • maxDegreeOfParallelismThe maximum number of selector tasks allowed to run concurrently; must be greater than zero.
  • cancellationTokenA token to observe for request to cancel the overall enumeration.

Returns

The sequence of transformed elements in the original input order; concurrency is limited to maxDegreeOfParallelism.

Method

ParallelSelectAsyncEnumerable

2 overloads
IAsyncEnumerable<TResult> ParallelSelectAsyncEnumerable<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, CancellationToken, Task<TResult>> body, int maxDegreeOfParallelism, int bufferMultiplier = 4, CancellationToken cancellationToken = default)

Produces an asynchronous sequence of results by applying body to each element of source, limiting concurrency to maxDegreeOfParallelism and preserving the input order. The internal channel capacity is capped at maxDegreeOfParallelism * bufferMultiplier.

Parameters

  • sourceThe input sequence to project; must not be null.
  • bodyA selector that projects an element to a Task{TResult}; it receives the element and a CancellationToken that is signaled when the operation is canceled.
  • maxDegreeOfParallelismThe maximum number of selector tasks that may run concurrently; must be greater than zero.
  • bufferMultiplierA multiplier used to compute the internal channel capacity as maxDegreeOfParallelism * bufferMultiplier (capped to int.MaxValue); must be at least 1.
  • cancellationTokenToken to observe for cooperative cancellation of the overall operation.

Returns

An IAsyncEnumerable{TResult} that yields projected results in the same order as the source sequence.

Exceptions

  • ArgumentNullExceptionThrown if source or body is null.
  • ArgumentOutOfRangeExceptionThrown if maxDegreeOfParallelism is less than or equal to zero or if bufferMultiplier is less than 1.
IAsyncEnumerable<TResult> ParallelSelectAsyncEnumerable<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, Task<TResult>> body, int maxDegreeOfParallelism, int bufferMultiplier = 4, CancellationToken cancellationToken = default)

Projects each element of source using the provided task-returning selector with bounded concurrency and yields the results in the same order as the source.

Parameters

  • sourceThe input sequence to project.
  • bodyA selector that produces a Task{TResult} for an input element. This overload does not pass or observe a CancellationToken to the selector.
  • maxDegreeOfParallelismThe maximum number of selector tasks allowed to run concurrently; must be greater than zero.
  • bufferMultiplierMultiplier applied to maxDegreeOfParallelism to determine internal channel capacity; must be at least 1.
  • cancellationTokenToken to cancel iteration and background work.

Returns

An IAsyncEnumerable{TResult} that yields projected results in the input order.

Exceptions

  • ArgumentNullExceptionsource or body is null.
  • ArgumentOutOfRangeExceptionmaxDegreeOfParallelism is less than or equal to 0, or bufferMultiplier is less than 1.
Type

StringExtensions

Provides extension methods for strings.

Method

SplitOnWhiteSpace

string[] SplitOnWhiteSpace(this string input)

Splits a string on any whitespace character, removing empty entries.

Parameters

  • inputThe string to split.

Returns

An array of substrings delimited by whitespace.