You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Expressions/Collections/CollectionExtensions.cs

24 lines
656 B

using System.Collections.ObjectModel;
namespace Connected.Expressions.Collections;
internal static class Extensions
{
public static ReadOnlyCollection<T> ToReadOnly<T>(this IEnumerable<T> sequence)
{
if (sequence is not ReadOnlyCollection<T> collection)
{
if (sequence is null)
collection = EmptyReadOnlyCollection<T>.Empty;
else
collection = new List<T>(sequence).AsReadOnly();
}
return collection;
}
private class EmptyReadOnlyCollection<T>
{
public static readonly ReadOnlyCollection<T> Empty = new List<T>().AsReadOnly();
}
}