C#: Extract extension types and members. Replacing invocations to static generated methods with invocation of extension type member.

This commit is contained in:
Michael Nebel
2026-02-04 15:57:16 +01:00
parent ab505e3281
commit edfdc9812f
8 changed files with 256 additions and 20 deletions

View File

@@ -119,5 +119,28 @@ namespace Semmle.Util
/// </summary>
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> items) where T : class =>
items.Where(i => i is not null)!;
/// <summary>
/// Splits the sequence at the given index.
/// </summary>
public static (IEnumerable<T>, IEnumerable<T>) SplitAt<T>(this IEnumerable<T> items, int index)
{
var left = new List<T>();
var right = new List<T>();
var i = 0;
foreach (var item in items)
{
if (i < index)
{
left.Add(item);
}
else
{
right.Add(item);
}
i++;
}
return (left, right);
}
}
}