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