Skip to content

Simplified manual member mapping #23

@Liamth99

Description

@Liamth99

Describe the solution you'd like:
At the moment the only way to manually map a member is using the ForMember<T1, T2>(TargetProp) attribute.

[GenerateMapper]
[Map<User, UserDto>]
public partial class UserMapper
{
    [ForMember<User, UserDto>(nameof(UserDto.DayOfBirth))]
    public static int GetDayOfBirth(User source) => source.DateOfBirth.UtcDateTime.Day;
}

This can be simplified for simple property assignments so that they dont need to call a method. A signiture like ForMember<T1, T2>(SourceProp, TargetProp) would probably work.

[GenerateMapper]
[Map<User, UserDto>]
[ForMember<User, UserDto>(nameof(source.DateOfBirth.UtcDateTime.Day), nameof(UserDto.DayOfBirth))]
public partial class UserMapper;

Only issue is nameof() will return the name of the final property not the whole expression.

Metadata

Metadata

Assignees

Labels

GeneratorThis issue focuses on the source generatorenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions