DotNext by .NET Foundation and Contributors

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

 IEnumerator<TSelf, T>

public interface IEnumerator<TSelf, T> where TSelf : struct, IEnumerator<TSelf, T>
Represents ad-hoc enumerator implemented as value type to avoid enumerator allocation and prevent the compiler to generate Dispose call.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Threading; namespace DotNext.Collections.Generic { [NullableContext(1)] [EditorBrowsable(EditorBrowsableState.Advanced)] public interface IEnumerator<[Nullable(0)] in TSelf, [Nullable(2)] out T> where TSelf : struct, IEnumerator<TSelf, T> { T Current { get; } bool MoveNext(); void Reset() { throw new NotSupportedException(); } IEnumerator<T> ToEnumerator(TSelf enumerator) { return new <IEnumerator>F8CC028BDE1CDD1AC29BF3DDB4981669BC4702D8256FB041147A1B7908FB6E4CB__BoxedEnumerator<TSelf, T>(enumerator, default(CancellationToken)); } IAsyncEnumerator<T> ToEnumerator(TSelf enumerator, CancellationToken token) { return new <IEnumerator>F8CC028BDE1CDD1AC29BF3DDB4981669BC4702D8256FB041147A1B7908FB6E4CB__BoxedEnumerator<TSelf, T>(enumerator, token); } } }