我想使用 automapper 在我的公共数据合同和我的 BD 模型之间进行映射。我需要将一个字符串参数传递到我的 MapProfile 并从我的属性中获取描述(在本例中为“代码”)。例如:
public class Source
{
public int Code { get; set; }
}
public class Destination
{
public string Description { get; set; }
}
public class Dic
{
public static string GetDescription(int code, string tag)
{
//do something
return "My Description";
}
}
public class MyProfile : Profile
{
protected override void Configure()
{
CreateMap<Destination, Source>()
.ForMember(dest => dest.Description,
opt => /* something */
Dic.GetDescription(code, tag));
}
}
public class MyTest
{
[Fact] …Run Code Online (Sandbox Code Playgroud)