Skip to content

Improvements for Mapster Tool - #1011

Open
DocSvartz wants to merge 7 commits into
MapsterMapper:developmentfrom
DocSvartz:feat-MapsterTool--publish
Open

Improvements for Mapster Tool #1011
DocSvartz wants to merge 7 commits into
MapsterMapper:developmentfrom
DocSvartz:feat-MapsterTool--publish

Conversation

@DocSvartz

@DocSvartz DocSvartz commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Improvements for generating mappers from interface :

  1. Added support mappers that use internal methods or properties.
  2. Added support for marking generated mapper attributes [MapsterToolGeneratedMapper]

@DocSvartz

This comment was marked as resolved.

@DocSvartz
DocSvartz requested a review from andrerav August 20, 2026 09:16
@DocSvartz

DocSvartz commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@andrerav
That is, if you emulate a cases that is not currently supported:

 public interface IMyTypeMapper
 {
     internal AddressDTO Map(Address p1);
     internal Expression<Func<AddressDTO, Address>> Projection { get; }
 }

or

internal interface IMyTypeMapper
{
    internal AddressDTO Map(Address p1);
    internal Expression<Func<AddressDTO, Address>> Projection { get; }
}

emulation step

  1. replace Address to internal

internal class Address

  1. in TypeDefinitions set

IsInternal = false,

we get valid mapper :

public partial class CustomerMapper : IMyTypeMapper 
{
    internal AddressDTO Map(Address p1)
    {
        return p1 == null ? null : new AddressDTO()
        {
            Id = p1.Id,
            City = p1.City,
            Country = p1.Country
        };
    }
    AddressDTO TemplateTest.IMyTypeMapper.Map(Address p1)
    {
        return p1 == null ? null : new AddressDTO()
        {
            Id = p1.Id,
            City = p1.City,
            Country = p1.Country
        };
    }
    internal Expression<Func<AddressDTO, Address>> Projection => p2 => new Address()
    {
        Id = p2.Id,
        City = p2.City,
        Country = p2.Country
    };
    Expression<Func<AddressDTO, Address>> TemplateTest.IMyTypeMapper.Projection => p2 => new Address()
    {
        Id = p2.Id,
        City = p2.City,
        Country = p2.Country
    };
}

I thought this shouldn't work, but the assembly with this class compiles and the mapper itself works when cast to the interface.🤔

…ic interfaces with internal member

and test refactoring
@DocSvartz

DocSvartz commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@andrerav If I'm not mistaken in the current implementation😃

Now mapper members are created correctly depending on the public/internal access modifiers specified for it or using for maping internal clases.

And IsInternal continues to work as before, forcing the creation of an internal mapper with an internal members.

1) property or method maks as public
2) property or method using only public clases
3) not using IsInternal atrribute
@andrerav

Copy link
Copy Markdown
Member

@DocSvartz Your approach is more general and solves both #399 and more. I closed my own PR, which had issues as you pointed out.

@DocSvartz DocSvartz changed the title feat mapster tool Improvements for Mapster Tool Aug 24, 2026
@DocSvartz

Copy link
Copy Markdown
Contributor Author

@andrerav Perhaps it's worth adding [MapsterToolGeneratedMapper] to Mapster.Core instead of generating it for each dotnet mapster mapper call?

Due to the use of the [Mapper] attribute on the interface, it is required to use at least Mapster.Core.

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.

mapster tool generates non-public interface method/property implementation

2 participants