-
-
Notifications
You must be signed in to change notification settings - Fork 2
Description
There is a naming collision issue in the source generator when defining custom property mappings. If the lambda expression inside the .From() method uses 's' as the input parameter name, the generated mapper code fails to compile.
This happens specifically within the ConfigureMapping method when working with MappingBuilder<TSource, TDestination>.
Minimal Reproducible Example:
public record Jedi(string Name, List<string> Enemies);
public record JediDto(string Name, int EnemiesCount);
[GenerateMapper]
public sealed partial class JediToDtoMapper : MapperProfile<Jedi, JediDto>
{
protected override void ConfigureMapping(MappingBuilder<Jedi, JediDto> mapping)
{
// Using 's' as the parameter name here causes the generated code to break
mapping.Property(d => d.EnemiesCount)
.From(s => s.Enemies.Count());
}
}
Actual Behavior:
The generator produces broken code that looks like this:
public override global::ArbiterMappingTest.JediDto? Map(global::ArbiterMappingTest.Jedi? source)
{
if (source is null)
return default;
return new global::ArbiterMappingTest.JediDto(
source.Name,
source.Enemiesource.Count() // <--- Error: 'Enemies' was incorrectly changed to 'Enemiesource'
);
}
As a result, the property name Enemies is incorrectly transformed into Enemiesource, and the code fails to compile.
Expected Behavior:
The generated code should correctly reference the properties of the source object regardless of the lambda parameter name used in the configuration. It should be: source.Enemies.Count().
Environment:
Library: Arbiter.Mapping
Version: 6.0.0
Target Framework: .NET 10
Workaround:
Renaming the lambda parameter from s to something else (e.g., src => src.Enemies.Count()) resolves the issue.