Skip to content

Commit 00996bd

Browse files
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
1 parent 4e18719 commit 00996bd

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

IntelliTect.Multitool.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1313
.github\workflows\deploy.yml = .github\workflows\deploy.yml
1414
Directory.Build.props = Directory.Build.props
1515
Directory.Packages.props = Directory.Packages.props
16+
global.json = global.json
1617
README.md = README.md
1718
EndProjectSection
1819
EndProject
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace IntelliTect.Multitool.Extensions;
2+
3+
/// <summary>
4+
/// Various Linq extensions
5+
/// </summary>
6+
public static class SystemLinqExtensions
7+
{
8+
/// <summary>
9+
/// Filters a sequence of values to only those that are not null.
10+
/// </summary>
11+
/// <typeparam name="T">The type of the elements of source.</typeparam>
12+
/// <param name="source">A <see cref="IEnumerable{T}"/> to filter.</param>
13+
/// <returns>An <see cref="IEnumerable{T}"/> that contains elements from the input that are not null.</returns>
14+
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source) where T : class?
15+
{
16+
return (IEnumerable<T>)source.Where(item => item is not null);
17+
}
18+
}

0 commit comments

Comments
 (0)