2015-02-06 107 views
0

这个通用方法工作得很好:Automapper仿制药测绘忽略属性

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); 
} 

任何想法?

感谢,

回答

3

试试这个:

Mapper.CreateMap<T, U>() 
    .ForMember(dest => dest.Password, opt => opt.Ignore())