Skip to content

Create map methods that dont require MapperContext when the configuration allows #3

@Liamth99

Description

@Liamth99

Describe the solution you'd like
When creating a mapper create 2 Map methods, one that takes the source and context (already exists) and another that takes just a source. This add a slight performance boost and for simple cases will mean the same performance as manual mapping.

This will only work if the mapper doesn't require the context (for example if preserve references is enabled, pre/post map methods and custom member methods require the context).

Example Source and generated code

[GenerateMapper]
[Map<Source, Dest>]
public partial class Mapper;

// Generates
public partial class Mapper
{
    public Dest Map(Source source)
    {
        ...
    }

    public Dest Map(Source source, MapperContext context)
    {
        ...
    }
}

// Instead of
public partial class Mapper
{
    public Dest Map(Source source,  MapperContext? context = null)
    {
        context ??= new();
        ...
    }
}

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