AppSurface Search
API Reference

Extensions

Type

StringExtensions

Source

Provides extension methods for strings.

Method

SplitOnWhiteSpace

string[] SplitOnWhiteSpace(this string? input)

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

Parameters

  • input
    The string to split.

Returns

An array of substrings delimited by whitespace.

Type

EnumerableExtensions

Source

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

Method

ParallelSelectAsync

3 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

  • source
    The sequence of input items.
  • body
    An asynchronous transform that receives an input item and a cancellation token and produces a result.
  • maxDegreeOfParallelism
    The maximum number of concurrent invocations of body ; must be greater than zero.
  • cancellationToken
    A token to observe while waiting for tasks to complete.

Returns

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

Exceptions

  • ArgumentNullException
    Thrown when source or body is null.
  • ArgumentOutOfRangeException
    Thrown when maxDegreeOfParallelism is less than or equal to zero.
  • OperationCanceledException
    The operation was canceled via cancellationToken .

Remarks

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

Task<IEnumerable<TResult>> ParallelSelectAsync<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, CancellationToken, Task<TResult>> body, int maxDegreeOfParallelism, CancellationToken cancellationToken, ILogger logger)

Projects each element of a sequence into a new form with bounded concurrency, preserves the input order of results, observes cancellationToken , and logs suppressed cleanup diagnostics through logger .

Parameters

  • source
    The sequence of input items.
  • body
    An asynchronous transform that receives an input item and a cancellation token and produces a result.
  • maxDegreeOfParallelism
    The maximum number of concurrent invocations of body ; must be greater than zero.
  • cancellationToken
    A token to observe while waiting for tasks to complete.
  • logger
    Logger for cleanup diagnostics that would otherwise be suppressed to preserve the primary exception.

Returns

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

Exceptions

  • ArgumentNullException
    Thrown when source , body , or logger is null.
  • ArgumentOutOfRangeException
    Thrown when maxDegreeOfParallelism is less than or equal to zero.
  • OperationCanceledException
    The 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

  • source
    The input sequence to project.
  • body
    A selector that produces a Task{TResult} for an input element; this selector does not receive or observe the supplied cancellationToken .
  • maxDegreeOfParallelism
    The maximum number of selector tasks allowed to run concurrently; must be greater than zero.
  • cancellationToken
    A 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

3 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

  • source
    The input sequence to project; must not be null.
  • body
    A selector that projects an element to a Task{TResult} ; it receives the element and a CancellationToken that is signaled when the operation is canceled.
  • maxDegreeOfParallelism
    The maximum number of selector tasks that may run concurrently; must be greater than zero.
  • bufferMultiplier
    A multiplier used to compute the internal channel capacity as maxDegreeOfParallelism * bufferMultiplier (capped to int.MaxValue ); must be at least 1.
  • cancellationToken
    Token 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

  • ArgumentNullException
    Thrown if source or body is null.
  • ArgumentOutOfRangeException
    Thrown 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, CancellationToken, Task<TResult>> body, int maxDegreeOfParallelism, int bufferMultiplier, CancellationToken cancellationToken, ILogger logger)

Produces an asynchronous sequence of results by applying body to each element of source , limiting concurrency, preserving input order, observing cancellationToken , and logging suppressed cleanup diagnostics through logger .

Parameters

  • source
    The input sequence to project; must not be null.
  • body
    A selector that projects an element to a Task{TResult} ; it receives the element and a cancellation token that is signaled when the operation is canceled.
  • maxDegreeOfParallelism
    The maximum number of selector tasks that may run concurrently; must be greater than zero.
  • bufferMultiplier
    A multiplier used to compute the internal channel capacity as maxDegreeOfParallelism * bufferMultiplier (capped to int.MaxValue ); must be at least 1.
  • cancellationToken
    Token to observe for cooperative cancellation of the overall operation.
  • logger
    Logger for cleanup diagnostics that would otherwise be suppressed to preserve the primary exception.

Returns

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

Exceptions

  • ArgumentNullException
    Thrown if source , body , or logger is null.
  • ArgumentOutOfRangeException
    Thrown 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

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

Returns

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

Exceptions

  • ArgumentNullException
    source or body is null.
  • ArgumentOutOfRangeException
    maxDegreeOfParallelism is less than or equal to 0, or bufferMultiplier is less than 1.