Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
@ZainnQureshii Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses #667
Mapster.Tool's generated
MapandMapToTargetextensions use the same collection expression builder as runtime mappings (src/Mapster.Tool/Generators.cs:673,src/Mapster.Tool/Generators.cs:685,src/Mapster/TypeAdapterConfig.cs:335). The old loop advanced the enumerator without disposing it. For example, whenAdapt<IEnumerable, List<int>>()throws while converting an item, a non-generic iterator'sfinallycan be skipped, leaving a reader or cursor open.The loop now disposes the enumerator in a
finallyblock. It callsDisposeon a non-nullIEnumerator<T>directly. For a non-genericIEnumerator, it usesas IDisposableand disposes the result when the cast succeeds, as C#foreachdoes (src/Mapster/Utils/ExpressionEx.cs:333). Regenerate existing extensions with the updated tool to pick up the fix.Collection, array, and multidimensional array mappings reach the shared builder through
ForLoopwhen they enumerate. Dictionary merges callForEachdirectly (src/Mapster/Adapters/CollectionAdapter.cs:213,src/Mapster/Adapters/ArrayAdapter.cs:124,src/Mapster/Adapters/MultiDimensionalArrayAdapter.cs:151,src/Mapster/Adapters/DictionaryAdapter.cs:158). The indexed paths acquire no enumerator for their loop.MapsterQueryablehands its provider's enumerator to the caller, which owns its lifetime (src/Mapster.EFCore/MapsterQueryable.cs:22,src/Mapster.EFCore/MapsterQueryable.cs:32).The checked-in course sample endpoint uses a LINQ projection. The benchmark’s generated enumeration loop reads the in-memory
List<Address>assigned toWorkAddresses(src/Sample.CodeGen/Controllers/SchoolController.cs:30,src/Benchmark/TestAdaptHelper.cs:77,src/Benchmark/CustomerMapper.g.cs:72).Verification
dotnet test src/Mapster.Tests/Mapster.Tests.csproj --framework net10.0 --filter FullyQualifiedName~MapToListDisposes --verbosity minimalran both disposal regressions. The non-generic case failed against the generic-only patch because its cleanup flag stayed false. Both passed with this patch and observed the expectedFormatException(src/Mapster.Tests/WhenMappingCollections.cs:252,src/Mapster.Tests/WhenMappingCollections.cs:273).dotnet build ./src/Mapster.slnanddotnet test ./src/Mapster.slnpassed ondevelopment, with 1,335 tests passed and 18 skipped across .NET 8, 9, and 10.extensioncommand. Generic and non-generic disposable enumerators recorded oneDisposecall on successful mapping and on conversion failure. Both extensions also mapped anArrayListwith a non-disposable enumerator.dotnet format styleanddotnet format whitespaceeach exited 2. Neither reported a diagnostic on a changed line.git diff --checkpassed.Prepared with AI assistance (Codex and Claude Code) and reviewed with GitHub Copilot.
🤖 Generated with Claude Code