![](/img/trans.png)
[英]AutoMapper with custom attribute[AutoMapper]: how to add a condition on a property
[英]How to add convention to specific property in AutoMapper
我正在使用AutoMapper,并且想为特定的属性名称添加约定,例如ABC_DEF-> ABCDEF。 我知道如何为所有属性名称添加约定。 如何只为特定属性添加? 谢谢。
对于所有属性名称:
AddMemberConfiguration().AddName<ReplaceName>(_ => _.AddReplace("Ä", "A").AddReplace("í", "i"));
编辑:
例如具有属性的类:
public class Test
{
public int ABC_PROP1 { get; set; }
public int ABC_PROP2 { get; set; }
public int ABC_PROP3 { get; set; }
public int CDE_PROP4 { get; set; }
public int EFG_PROP5 { get; set; }
}
我只想在以ABC开头的属性中替换“ _”。 但是没有MapForm。 可以使用约定吗?
您可以将MapFrom用作特定的属性名称。 它使您可以从一个属性重定向到另一个属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.