可以进行变量名指向和类型转换
Mapper.Initialize(cfg =>
{
//int转string
cfg.CreateMap<int, string>().ConvertUsing(s => Convert.ToString(s));
cfg.CreateMap<Source, Deviceware>().ForMember(d => d.sex2, d => d.MapFrom(src => src.sex1));
});
Mapper.AssertConfigurationIsValid();//针对每个问题抛异常
var s = new Source
{
sex1 = 0
};
Deviceware dac = Mapper.Map<Source, Deviceware>(s);
var sdac = dac.sex2;
Console.WriteLine(typeof(string).IsInstanceOfType(sdac));
Console.WriteLine(sdac);
实体类如下
public class Deviceware
{
public string DeviceNumber { get; set; }
public string SIMCCID { get; set; }
//0为女 1为男
public string sex2 { get; set; }
}
public class Source
{
public string DeviceNumber { get; set; }
public string SIMCCID { get; set; }
//0为女 1为男
public int sex1 { get; set; }
}