如何从另一个文件引用?

问题描述 投票:0回答:1
  • 有A映射器/B映射器文件。

  • 地图制作者有.

  • 我想在B映射器中引用A映射器文件的“CommonWhere”。

有办法吗?

我在文件B中尝试了以下公式作为参考,但没有成功。

B 映射器文件 ->

spring-mybatis
1个回答
0
投票
// In Mapper A
public class MapperAProfile : Profile
{
    public MapperAProfile()
    {
        CreateMap<SourceType, DestinationType>()
            .ForMember(dest => dest.CommonWhere, opt => opt.MapFrom(src => src.SomeProperty));
    }
}

// In Mapper B
public class MapperBProfile : Profile
{
    public MapperBProfile()
    {
        // Use the same profile from Mapper A
        AddProfile<MapperAProfile>();

        // Add additional configurations specific to Mapper B
        CreateMap<AnotherSourceType, AnotherDestinationType>();
    }
}

在此示例中,

MapperBProfile
包含MapperAProfile,这意味着它继承了MapperAProfile的设置。然后可以添加 Mapper B 特有的其他设置。

© www.soinside.com 2019 - 2024. All rights reserved.