-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add System.Linq WhereNotNull() extension (#100)
This solves the case of `foreach (string folder in folders.Where(x => !string.IsNullOrWhiteSpace(x)))` not working by itself and needing to cast it or similar
- Loading branch information
1 parent
4e18719
commit 00996bd
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace IntelliTect.Multitool.Extensions; | ||
|
||
/// <summary> | ||
/// Various Linq extensions | ||
/// </summary> | ||
public static class SystemLinqExtensions | ||
{ | ||
/// <summary> | ||
/// Filters a sequence of values to only those that are not null. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the elements of source.</typeparam> | ||
/// <param name="source">A <see cref="IEnumerable{T}"/> to filter.</param> | ||
/// <returns>An <see cref="IEnumerable{T}"/> that contains elements from the input that are not null.</returns> | ||
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source) where T : class? | ||
{ | ||
return (IEnumerable<T>)source.Where(item => item is not null); | ||
} | ||
} |