DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="0.5.1" />

 SingletonList<T>

using System; using System.Collections; using System.Collections.Generic; namespace DotNext.Collections.Generic { internal struct SingletonList<T> : IReadOnlyList<T>, IEnumerable<T>, IEnumerable, IReadOnlyCollection<T> { internal struct Enumerator : IEnumerator<T>, IEnumerator, IDisposable { private bool requested; public T Current { get; } object IEnumerator.Current { get { return Current; } } internal Enumerator(T element) { Current = element; requested = false; } void IDisposable.Dispose() { this = default(Enumerator); } public bool MoveNext() { if (!requested) return requested = true; return false; } public void Reset() { requested = false; } } internal T Item1; T IReadOnlyList<T>.this[int index] { get { if (index != 0) throw new IndexOutOfRangeException(ExceptionMessages.IndexShouldBeZero); return Item1; } } int IReadOnlyCollection<T>.Count { get { return 1; } } public Enumerator GetEnumerator() { return new Enumerator(Item1); } IEnumerator<T> IEnumerable<T>.GetEnumerator() { return GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } }