Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic IEnumerator not disposed #667

Open
andy-clymer opened this issue Dec 7, 2023 · 0 comments
Open

Generic IEnumerator not disposed #667

andy-clymer opened this issue Dec 7, 2023 · 0 comments

Comments

@andy-clymer
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant