Reputation: 19933
This generic method works fine :
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);
}
I have this interface :
public interface IPassword
{
string Password { get; set; }
}
I'd like ignore this property ('Password
')but I don't have 'ignore' in the 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);
}
Any idea ?
Thanks,
Upvotes: 1
Views: 800
Reputation: 6638
Try this:
Mapper.CreateMap<T, U>()
.ForMember(dest => dest.Password, opt => opt.Ignore())
Upvotes: 4