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.
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|