在自动映射器中将两个或多个属性映射到一个 属性

Map two or more properties to one property in automapper

我试图在自动映射器中将两个字符串映射到一个字符串。

我认为这与使用 this 有关,但我无法理解它。

这是错误的,但像这样:

CreateMap<TestClass, SecondClass.ThirdClass>.ForMember(x => x.Test, y => y.MapFrom(z => z.FirstString && z => z.SecondString)) 


public class TestClass {    
        public string FirstString { get; set; }
        public string SecondString { get; set; }
}

public class SecondClass {
    public class ThirdClass {
        public string Test { get; set; }
    }
}

我希望测试包含 FirstString + SecondString。

您可以只使用字符串插值 - y => y.MapFrom(z => $"{z.FirstString} {z.SecondString)}")