Open
Description
If you have a struct that implicitly acts as an Enumerator:
public struct EnumeratorStruct : IDisposable
{
public int Current { get; }
public bool MoveNext() => foo;
public EnumeratorStruct GetEnumerator() => this;
public void Dispose() => Console.WriteLine("Disposed");
}
If you use EnumeratorStruct
as the supplier in a foreach
statement, EnumeratorStruct.Dispose()
is called but the analyzer still gives the IDISP004 warning.
All examples bellow are non-compliant despite being false-positives.
foreach (int element in new EnumeratorStruct())
{
...
}
public static EnumeratorStruct Enumerate(this Foo source) => new EnumeratorStruct(source);
Foo source = new Foo();
foreach (int element in source.Enumerate())
{
...
}
EnumeratorStruct enumerator = new EnumeratorStruct();
foreach (int element in enumerator)
{
...
}
Metadata
Metadata
Assignees
Labels
No labels