[英]Automapper ignore property on generics mapping
這種通用方法工作正常:
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; }
}
我想忽略這個屬性(“ Password
”),但我在智能感知中沒有“忽略”
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);
}
任何的想法 ?
謝謝,
嘗試這個:
Mapper.CreateMap<T, U>()
.ForMember(dest => dest.Password, opt => opt.Ignore())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.