EnumerableExtensions Class
Provides extension methods for types implementing IEnumerable or IEnumerable<T>.
public static class EnumerableExtensionsMethods
| Name | Description |
|---|---|
| IEnumerable.DisposeAll() | Disposes all items that implement either IDisposable or IAsyncDisposable. If an item implements both, only IDisposable is considered. |
| IEnumerable.DisposeAllAsync() | Asynchronously disposes all items that implement either IAsyncDisposable or IDisposable. If an item implements both, only IAsyncDisposable is considered. |
| IEnumerable<T>.WhereNot(Func<T, bool>) | Filters a sequence of values based on a predicate, taking only those that do not satisfy the condition set by the predicate. |
| WhereNotNull<T>(IEnumerable<T?>) | Filters a sequence of nullable values, taking only those that are not null. |
| WhereNotNull<T>(IEnumerable<T?>) | Filters a sequence of nullable values, taking only those that are not null. |
| IEnumerable<string?>.WhereNotNullOrEmpty() | Filters a sequence of nullable strings, taking only those that are neither null nor the empty string. |
| IEnumerable<string?>.WhereNotNullOrWhiteSpace() | Filters a sequence of nullable strings, taking only those that are not null, nor empty, nor consisting only of white-space characters. |
IEnumerable.DisposeAll()
Disposes all items that implement either IDisposable or IAsyncDisposable.
If an item implements both, only IDisposable is considered.
extension(IEnumerable @this)
{
public void DisposeAll()
}Parameters
thisIEnumerable- The
IEnumerableinterface on which this method is called.
Exceptions
ArgumentNullExceptionthisisnull.AggregateException- One or more exceptions were raised by the
IDisposable.Disposeand/orIAsyncDisposable.DisposeAsyncmethods of items.
Remarks
This method will not dispose disposable ref structs.
IEnumerable.DisposeAllAsync()
Asynchronously disposes all items that implement either IAsyncDisposable or IDisposable.
If an item implements both, only IAsyncDisposable is considered.
extension(IEnumerable @this)
{
public ValueTask DisposeAllAsync()
}Parameters
thisIEnumerable- The
IEnumerableinterface on which this method is called.
Returns
ValueTask A ValueTask that represents the ongoing operation.
Exceptions
ArgumentNullExceptionthisisnull.AggregateException- One or more exceptions were raised by the
IAsyncDisposable.DisposeAsyncand/orIDisposable.Disposemethods of items.
Remarks
This method will not dispose disposable ref structs.
IEnumerable<T>.WhereNot(Func<T, bool>)
Filters a sequence of values based on a predicate, taking only those that do not satisfy the condition set by the predicate.
extension<T>(IEnumerable<T> @this)
{
public IEnumerable<T> WhereNot(Func<T, bool> predicate)
}Type parameters
T- The type of the elements of
this.
Parameters
thisIEnumerable<T>- An
IEnumerable<T>to filter. predicateFunc<T, bool>- A function to test each element for a condition.
Returns
IEnumerable<T> An IEnumerable<T> that contains elements from the input sequence that do not satisfy the condition defined by predicate.
Exceptions
ArgumentNullExceptionthisisnull. - or -predicateisnull.
WhereNotNull overloads
WhereNotNull<T>(IEnumerable<T?>)
Filters a sequence of nullable values, taking only those that are not null.
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> @this) where T : structType parameters
T- The type of the elements of
this.
Parameters
thisIEnumerable<T?>- An
IEnumerable<T>to filter.
Returns
IEnumerable<T> An IEnumerable<T> that contains the values of the elements from the input sequence that are not null.
Exceptions
ArgumentNullExceptionthisisnull.
WhereNotNull<T>(IEnumerable<T?>)
Filters a sequence of nullable values, taking only those that are not null.
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> @this) where T : classType parameters
T- The type of the elements of
this.
Parameters
thisIEnumerable<T?>- An
IEnumerable<T>to filter.
Returns
IEnumerable<T> An IEnumerable<T> that contains elements from the input sequence that are not null.
Exceptions
ArgumentNullExceptionthisisnull.
IEnumerable<string?>.WhereNotNullOrEmpty()
Filters a sequence of nullable strings, taking only those that are neither null nor the empty string.
extension(IEnumerable<string?> @this)
{
public IEnumerable<string> WhereNotNullOrEmpty()
}Parameters
thisIEnumerable<string?>- An IEnumerable<string?> to filter.
Returns
IEnumerable<string> An IEnumerable<string> that contains elements from the input sequence that are neither null nor the empty string.
Exceptions
ArgumentNullExceptionthisisnull.
IEnumerable<string?>.WhereNotNullOrWhiteSpace()
Filters a sequence of nullable strings, taking only those that are not null, nor empty, nor consisting only of white-space characters.
extension(IEnumerable<string?> @this)
{
public IEnumerable<string> WhereNotNullOrWhiteSpace()
}Parameters
thisIEnumerable<string?>- An IEnumerable<string?> to filter.
Returns
IEnumerable<string> An IEnumerable<string> that contains elements from the input sequence that are not null, nor empty, nor consisting only of white-space characters.
Exceptions
ArgumentNullExceptionthisisnull.