简体   繁体   English

如何将约定添加到AutoMapper中的特定属性

[英]How to add convention to specific property in AutoMapper

I'm using AutoMapper and I want to add Convention for specific property name, such as ABC_DEF -> ABCDEF. 我正在使用AutoMapper,并且想为特定的属性名称添加约定,例如ABC_DEF-> ABCDEF。 I know how to add convention for all properties names. 我知道如何为所有属性名称添加约定。 How to add only for specific property? 如何只为特定属性添加? Thanks. 谢谢。

For all property names: 对于所有属性名称:

AddMemberConfiguration().AddName<ReplaceName>(_ => _.AddReplace("Ä", "A").AddReplace("í", "i"));

EDIT: 编辑:

For example class with properties: 例如具有属性的类:

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

And I want to replace "_" only in properties starts with ABC. 我只想在以ABC开头的属性中替换“ _”。 But without MapForm. 但是没有MapForm。 Is it possible use convention? 可以使用约定吗?

You can use MapFrom for a specific property name. 您可以将MapFrom用作特定的属性名称。 It lets you redirect from one property to another. 它使您可以从一个属性重定向到另一个属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM