mapperly icon indicating copy to clipboard operation
mapperly copied to clipboard

Raise diagnostic for memberpaths that mistakenly specify the type name

Open TimothyMakkison opened this issue 2 years ago • 0 comments

A common mistake with MapProperty is to include the type name as part of the string. This usually occurs when mapping a deeply nested property and the user removes nameof and adds parentheses. Mistakenly adding the enclosing type name to the path.

Note that C# does not allow properties to have the same name as the enclosing type.

public record Dog(Tail tail);

public record Tail(Colour colour);

// Diagnostic should be emitted because the first member path has the same name as the type
[MapProperty("Colour", "Dog.Tail.Colour")]
public static partial Dog Map(Table src);

This should probably also check MapperIgnoreTarget etc .

See #1030

TimothyMakkison avatar Dec 23 '23 16:12 TimothyMakkison