Skip to content

Commit

Permalink
Remote DrainToImmutable() extension method
Browse files Browse the repository at this point in the history
Since moving to System.Collections.Immutable 8.0, this extension method is no longer needed.
  • Loading branch information
DustinCampbell committed Jul 16, 2024
1 parent 19f2f7f commit 90cbe54
Showing 1 changed file with 0 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,6 @@ public static void SetCapacityIfLarger<T>(this ImmutableArray<T>.Builder builder
}
}

/// <summary>
/// Returns the current contents as an <see cref="ImmutableArray{T}"/> and sets
/// the collection to a zero length array.
/// </summary>
/// <remarks>
/// If <see cref="ImmutableArray{T}.Builder.Capacity"/> equals
/// <see cref="ImmutableArray{T}.Builder.Count"/>, the internal array will be extracted
/// as an <see cref="ImmutableArray{T}"/> without copying the contents. Otherwise, the
/// contents will be copied into a new array. The collection will then be set to a
/// zero-length array.
/// </remarks>
/// <returns>An immutable array.</returns>
public static ImmutableArray<T> DrainToImmutable<T>(this ImmutableArray<T>.Builder builder)
{
#if NET8_0_OR_GREATER
return builder.DrainToImmutable();
#else
if (builder.Count == 0)
{
return [];
}

if (builder.Count == builder.Capacity)
{
return builder.MoveToImmutable();
}

var result = builder.ToImmutable();
builder.Clear();
return result;
#endif
}

public static ImmutableArray<TResult> SelectAsArray<T, TResult>(this ImmutableArray<T> source, Func<T, TResult> selector)
{
return source switch
Expand Down

0 comments on commit 90cbe54

Please sign in to comment.