0

当我尝试编译 mapster 配置时,它会AmbiguousMatchException在这个特定的映射中抛出一个:


config.NewConfig<Example, ExampleVM>()
    .Map(dest => dest.Id, src => src.Id)
    .Map(dest => dest.Prop1, src => src.Prop1)
    .Map(dest => dest.Prop2, src => src.Prop2)
    .Map(dest => dest.Prop3, src => src.Prop3)
    .Map(dest => dest.Prop1, src => src.Prop1);


config.NewConfig<ExampleVM, Example>()
    .Map(dest => dest.Prop2, src => src.Prop2);



public class Example{
    public int Prop1 {get;set;}
    public DateTime? Prop2 {get;set;}
    public string Prop3 {get;set;}
    public AnotherClass Prop1 {get;set;}
}

public class AnotherClass {

}


public class ExampleVM{
    public int Prop1 {get;set;}
    public DateTime? Prop2 {get;set;}
    public string Prop3 {get;set;}
}


并且异常不会告知什么是错误的。

在更新到 Mapster 5.0 之前,一切正常。

4

1 回答 1

0

实际上问题在于,由于某种原因,在这个新的 Mapster 版本中,即使属性类型不同,也无法映射具有相同名称的探测器。

我需要做的是删除重复的映射线并重命名属性之一:


config.NewConfig<Example, ExampleVM>()
    .Map(dest => dest.Id, src => src.Id)
    .Map(dest => dest.Prop1, src => src.Prop1)
    .Map(dest => dest.Prop2, src => src.Prop2)
    .Map(dest => dest.Prop3, src => src.Prop3);


config.NewConfig<ExampleVM, Example>()
    .Map(dest => dest.Prop2, src => src.Prop2);



public class Example{
    public int Prop1 {get;set;}
    public DateTime? Prop2 {get;set;}
    public string Prop3 {get;set;}
    public AnotherClass Prop1Data {get;set;}
}

public class AnotherClass {

}


public class ExampleVM{
    public int Prop1 {get;set;}
    public DateTime? Prop2 {get;set;}
    public string Prop3 {get;set;}
}


于 2020-07-22T17:36:37.263 回答