Mapster
Mapster copied to clipboard
Generic IEnumerator not disposed
I'm using Mapster.Tool to generate extension methods from my mapping registrations like so:
config.NewConfig<TSource, TDestination>().GenerateMapper(MapType.Map | MapType.MapToTarget);
When inspecting the generated code I noticed that anywhere GetEnumerator() is used, the generic Enumerator is never disposed.
This is a snippet of what is being generated:
...
IEnumerator<string> enumerator = p2.GetEnumerator();
while (enumerator.MoveNext())
{
string item = enumerator.Current;
result.Add(item);
}
return result;
I believe what it should be generating is the following:
using IEnumerator<string> enumerator = p2.GetEnumerator();
while (enumerator.MoveNext())
{
string item = enumerator.Current;
result.Add(item);
}
return result;
I'm not sure if this issue arises in other areas (e.g. generated code from interfaces) as I haven't tested it personally, but I would expect the Mapster.Tool generates the code the same way.