[英]How to ignore properties of a specific type when using Automapper?
我们假设我有两种类型:
class Type1
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
public string Prop3 { get; set; }
}
class Type2
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
public TypeToIgnore Prop3 { get; set; }
}
我想在这两种类型之间进行映射,但忽略具有TypeToIgnore
所有属性。 这是因为我使用反射迭代所有这些并在它们上进行一些自定义映射。
在一个派生自Profile
的类中,我可以为每个我不想映射的成员添加一个Ignore
,如下所示:
CreateMap<Type2, Type1>().ForMember(x => x.Prop3, y => y.Ignore());
或者我可以使用属性上的IgnoreMapAttribute
来忽略,但考虑到生产代码,我有很多,有没有更容易忽略某些特定类型的方法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.