假设我有一个源类:
public class Source
{
//Several properties that can be mapped to DerivedBase and its subclasses
}
Run Code Online (Sandbox Code Playgroud)
还有一些目的地类:
public class DestinationBase
{
//Several properties
}
public class DestinationDerived1 : DestinationBase
{
//Several properties
}
public class DestinationDerived2 : DestinationBase
{
//Several properties
}
Run Code Online (Sandbox Code Playgroud)
然后我希望派生的目标类继承baseclass的automapper配置,因为我不想重复它,有没有办法实现这个?
Mapper.CreateMap<Source, DestinationBase>()
.ForMember(...)
// Many more specific configurations that should not have to be repeated for the derived classes
.ForMember(...);
Mapper.CreateMap<Source, DestinationDerived1 >()
.ForMember(...);
Mapper.CreateMap<Source, DestinationDerived2 >()
.ForMember(...);
Run Code Online (Sandbox Code Playgroud)
当我像这样写它时根本不使用基本映射,包含似乎对我没有帮助.
编辑:这是我得到的:
public class Source
{
public string …Run Code Online (Sandbox Code Playgroud)