Skip to content

Improved LINQ method generation for enumerable properties#60

Merged
mrtaikandi merged 1 commit intomainfrom
dev/linq-improvement
May 22, 2025
Merged

Improved LINQ method generation for enumerable properties#60
mrtaikandi merged 1 commit intomainfrom
dev/linq-improvement

Conversation

@mrtaikandi
Copy link
Copy Markdown
Owner

This pull request introduces enhancements to the mapping functionality, particularly focusing on handling primitive types and improving LINQ-based mapping for enumerable properties. It also includes minor refactoring for code clarity and additional test cases to ensure the correctness of the changes.

Enhancements to Primitive Type Handling:

  • Updated IsPrimitiveType method in SymbolExtensions.cs to include System.Guid as a primitive type and refactored logic for clarity. ([[1]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-ba40976ead2ddf1740a1927cac5efb74a50988e800b9bc1948f12d2a6de7fdd9L56-R63), [[2]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-ba40976ead2ddf1740a1927cac5efb74a50988e800b9bc1948f12d2a6de7fdd9L69-R77))
  • Added ElementTypeIsPrimitive property to TypeMapping and updated its initialization to determine if the element type of a collection is primitive. ([[1]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-3143b6427db7c84654129c68218fa169962faf46f10eda3e209221dcedeaebebR15), [[2]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-3143b6427db7c84654129c68218fa169962faf46f10eda3e209221dcedeaebebR66))

Improvements to LINQ-based Mapping:

  • Enhanced mapping logic in ArrayPropertyMappingGenerator.cs and GenericEnumerablePropertyMappingGenerator.cs to use LINQ methods directly when both source and target element types are primitive. ([[1]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-20a20ade2e68d6800c40d3eac7bf1ab7fadf37ef6cb4bad9517f030eb82bb748R186), [[2]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-20a20ade2e68d6800c40d3eac7bf1ab7fadf37ef6cb4bad9517f030eb82bb748R203), [[3]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-6d173185170641afdd1b796b163083c02a5c9e2d4220b5b448f11abad3df8a08R75-R84))
  • Updated TypeConverterPropertyMappingGenerator.cs to handle primitive types efficiently in mapping scenarios. ([src/MapTo/Generators/Properties/TypeConverterPropertyMappingGenerator.csR58-R73](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-a6dcad795c583752ce7a70894220007a4fcc67ab702983cf888500106180cc22R58-R73))

Refactoring and Code Simplification:

  • Simplified GetElementType logic in SymbolExtensions.cs to return the named type symbol directly. ([src/MapTo/CodeAnalysis/SymbolExtensions.csL185-R192](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-ba40976ead2ddf1740a1927cac5efb74a50988e800b9bc1948f12d2a6de7fdd9L185-R192))
  • Replaced WriteIf with WriteLineIf in multiple generators for better readability and consistency. ([[1]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-20a20ade2e68d6800c40d3eac7bf1ab7fadf37ef6cb4bad9517f030eb82bb748L175-R175), [[2]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-6d173185170641afdd1b796b163083c02a5c9e2d4220b5b448f11abad3df8a08L63-R63))

Test Coverage Enhancements:

  • Added new test cases to validate mapping of enumerable properties with primitive types, ensuring correct LINQ method usage (ToList, ToArray, etc.). ([test/MapTo.Tests/MapFromCollectionTests.csR577-R674](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-365ce719a1c6eefbbfd8ad82140bbc63f781fe8172aeb7797abe4ec9a2938692R577-R674))
  • Refactored existing tests for better readability and alignment with new mapping logic. ([[1]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-365ce719a1c6eefbbfd8ad82140bbc63f781fe8172aeb7797abe4ec9a2938692L79-R80), [[2]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-365ce719a1c6eefbbfd8ad82140bbc63f781fe8172aeb7797abe4ec9a2938692L202-R205))

Bug Fixes:

  • Fixed mapping logic in EnumerableTypeConverterResolver.cs to handle cases where the element type is primitive or has a MapFrom attribute. ([[1]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-4759406929debd1363acffc70084fccc1e8befdf7e668d2627c41be99de62ef8R24-R43), [[2]](https://github.com/mrtaikandi/MapTo/pull/60/files#diff-4759406929debd1363acffc70084fccc1e8befdf7e668d2627c41be99de62ef8L41-R53))

@mrtaikandi mrtaikandi merged commit d1960dd into main May 22, 2025
1 check failed
@mrtaikandi mrtaikandi deleted the dev/linq-improvement branch May 22, 2025 16:53
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

Successfully merging this pull request may close these issues.

1 participant