Skip to content

Conversation

@Ten-James
Copy link
Owner

This pull request introduces support for mapping properties from base classes in both entities and DTOs, ensuring that inherited properties are correctly handled during mapping operations. The changes include enhancements to the source generator logic, new shared base classes for entities and DTOs, and new integration tests to verify base class property mapping.

Support for inheritance in mapping:

  • Added BaseEntity and BaseDto abstract classes with common properties (Id, CreatedAt, UpdatedAt, etc.), and introduced a Vehicle entity and corresponding DTOs that inherit from these base classes. This enables testing and demonstration of inheritance-aware mapping. [1] [2]
  • Updated the mapping source generator (MapperGenerator.cs and MappingOptions.cs) to collect all properties, including those inherited from base classes, when generating mapping code. This ensures that both direct and inherited properties are mapped automatically. [1] [2] [3] [4]

Improvements to generated mapping code:

  • Modified the generator to use fully qualified type names and target namespaces when generating mapping methods and property assignments, improving compatibility across namespaces and resolving type ambiguities. [1] [2]
  • Enhanced the handling of property type mismatches in the generated code: if a property exists in both source and target but has different types, the generator now uses the mapper to convert the property value. [1] [2]

Testing and validation:

  • Added integration tests to verify that properties from base classes are correctly mapped for both MapFrom and MapTo scenarios, covering both the entity-to-DTO and DTO-to-entity directions.

James and others added 3 commits January 22, 2026 21:01
This commit fixes two major bugs in the source generator:

1. **Missing fully qualified type names**: The generator now uses fully
   qualified type names (including namespace) for all type references in
   generated code. This prevents compilation errors when source and target
   classes are in different namespaces.

   Changes in MappingOptions:
   - Added TargetNamespace property to store target class namespace
   - Added TargetFullName property to get fully qualified target name
   - Updated Create method to extract and store target namespace

   Changes in MapperGenerator:
   - Use TargetFullName instead of just TargetName for all type references
   - Add using directive for target namespace when it differs from current
   - Apply to MapFrom method signature, MapTo return type, and all instantiations

2. **Missing type conversion in MapTo**: The MapTo method now properly
   handles properties with different types between source and target classes
   by using mapper.Map<T>() for type conversion, matching the behavior of
   MapFrom.

   Changes in MapperGenerator:
   - Added type checking in MapTo property mapping loop
   - Use mapper.Map<T>() when property types don't match
   - Direct assignment when property types match

All existing tests pass. The example project builds successfully with the fixes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit adds comprehensive integration tests for derived fields
and begins work on supporting property inheritance from base classes.

Changes:
- Added Vehicle entity and DTOs with inheritance for testing
- Added integration tests for base class property mapping
- Refactored property handling to use PropertyInfo model
- Updated all property access to work with new model

Current Status:
- Namespace and type conversion fixes are working correctly
- Integration tests compile and demonstrate expected behavior
- Base class property mapping is partially implemented

Known Issue:
The inheritance feature encounters "Syntax node is not within syntax tree"
errors when accessing properties from base classes in different files.
This requires additional work to properly resolve properties across
compilation units using the semantic model.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@Ten-James Ten-James merged commit 5db2f70 into main Jan 22, 2026
1 check passed
@Ten-James Ten-James deleted the fix/namespace-and-derived-fields branch January 22, 2026 20:22
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.

2 participants