Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Mapster Tool Extensions generation fails to generate from internal extension methods

Open Shidzy2 opened this issue 2 years ago • 0 comments

 public static partial class GeneratedMapperExtensionClass
{
    private static Func<decimal, decimal> ToExt1;
    
    public static DestinationClass AdaptToDestinationClass (this SourceClass p1)
    {
        return p1 == null ? null : new DestinationClass ()
        {
            Property = AdapterRegister.Convert(ToExt1.Invoke(p1.Property ))
        };
    }
}

IRegister class

 public sealed class AdapterRegister : IRegister
 {
     public void Register(TypeAdapterConfig config)
{

    
    config.NewConfig<SourceClass , DestinationClass>()
         .Map(dst => dst.Property , src => Convert(src.Property .ToExt())) // using ToExt from internal extension class
         .GenerateMapper(MapType.Map);

}

public static decimal Convert(decimal c)
{
    return c;
}
 }

internal extension class

 internal static class TetsExt
 {
     internal static decimal ToExt(this decimal d)
     {
         return d * 1.0001m;
     }
 }

Command to generate extension:

<Target Name="TestAfterBuild" AfterTargets="Build"> <Exec Command="dotnet mapster extension -a &quot;$(OutputPath)$(TargetFileName)&quot; -n &quot;$(RootNamespace).Adapters&quot; -o &quot;$(ProjectDir)Adapters&quot;" /> </Target>

So as you see from this example when using internal static method it generates it as private static Func<decimal, decimal> ToExt1; Is there any way to fix this?

Shidzy2 avatar Aug 08 '23 14:08 Shidzy2