diff --git a/MoreLinq/CollectionLike.cs b/MoreLinq/CollectionLike.cs index 761cb401f..42c642976 100644 --- a/MoreLinq/CollectionLike.cs +++ b/MoreLinq/CollectionLike.cs @@ -49,4 +49,16 @@ public CollectionLike(IReadOnlyCollection collection) public IEnumerator GetEnumerator() => _rw?.GetEnumerator() ?? _ro?.GetEnumerator() ?? Enumerable.Empty().GetEnumerator(); } + + static class CollectionLike + { + public static CollectionLike? TryAsCollectionLike(this IEnumerable source) => + source switch + { + null => throw new ArgumentNullException(nameof(source)), + ICollection collection => new(collection), + IReadOnlyCollection collection => new(collection), + _ => null + }; + } } diff --git a/MoreLinq/ListLike.cs b/MoreLinq/ListLike.cs index 018dbb152..7e774c47f 100644 --- a/MoreLinq/ListLike.cs +++ b/MoreLinq/ListLike.cs @@ -54,8 +54,6 @@ public ListLike(IReadOnlyList list) static class ListLike { public static ListLike AsListLike(this List list) => new((IList)list); - public static ListLike AsListLike(this IList list) => new(list); - public static ListLike AsListLike(this IReadOnlyList list) => new(list); public static ListLike ToListLike(this IEnumerable source) => source.TryAsListLike() ?? source.ToList().AsListLike(); @@ -64,8 +62,8 @@ public static ListLike ToListLike(this IEnumerable source) source switch { null => throw new ArgumentNullException(nameof(source)), - IList list => list.AsListLike(), - IReadOnlyList list => list.AsListLike(), + IList list => new(list), + IReadOnlyList list => new(list), _ => null }; } diff --git a/MoreLinq/MoreEnumerable.cs b/MoreLinq/MoreEnumerable.cs index 18aa05dd4..666158121 100644 --- a/MoreLinq/MoreEnumerable.cs +++ b/MoreLinq/MoreEnumerable.cs @@ -27,15 +27,6 @@ namespace MoreLinq public static partial class MoreEnumerable { - internal static CollectionLike? TryAsCollectionLike(this IEnumerable source) => - source switch - { - null => throw new ArgumentNullException(nameof(source)), - ICollection collection => new CollectionLike(collection), - IReadOnlyCollection collection => new CollectionLike(collection), - _ => null - }; - static int CountUpTo(this IEnumerable source, int max) { if (source == null) throw new ArgumentNullException(nameof(source));