这种通用方法很好用:
public static U PropertyAutomapper<T, U>(T source)
where T : class, new()
where U : class, new()
{
Mapper.CreateMap(typeof(T), typeof(U));
return Mapper.Map<T, U>(source);
}
我有这个界面:
public interface IPassword
{
string Password { get; set; }
}
我想忽略这个属性(&#39; Password
&#39;)但我没有忽略&#39;在intelissense
public static U PropertyAutomapperNoPassword<T, U>(T source)
where T : IPassword
where U : IPassword
{
Mapper.CreateMap(typeof(T), typeof(U))...
return Mapper.Map<T, U>(source);
}
有什么想法吗?
谢谢,
答案 0 :(得分:3)
试试这个:
Mapper.CreateMap<T, U>()
.ForMember(dest => dest.Password, opt => opt.Ignore())