MapsterMapper / MapsterMapper/Mapster
Generic IEnumerator not disposed
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.2k
- Forks
- 410
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
I'm using Mapster.Tool to generate extension methods from my mapping registrations like so:
```csharp
config.NewConfig().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:
```csharp
...
IEnumerator 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:
```csharp
using IEnumerator 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Mapster.Tool and reproduce the generated extension method using the shown NewConfig().GenerateMapper(...) registration. Inspect the GetEnumerator() generation path, including generated code from interfaces if applicable; done means generated generic enumerators are disposed while iteration behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100