开发者

AUtomapper - custom property mapping

开发者 https://www.devze.com 2023-03-05 08:50 出处:网络
Usually the property names are the same,but many properties have on one side a prefix. Classes may look like this

Usually the property names are the same,but many properties have on one side a prefix.

Classes may look like this

public class User
{
     public string Name{ get; set; }
     public string Adress{ get; set; }
     public string SureName{ get; set; }
} 

public class UserEntity开发者_开发技巧
{
     public string Name{ get; set; }
     public string XxxAdress{ get; set; }
     public string YyyYyySureName{ get; set; }
} 

Is it possible to create a rule,which would compare the property names using the EndsWith() function ?

I don't want use the .ForMember on every object, there are to many objects to maintain this.


You can use the RecognizePrefixes or RecognizeDestinationPrefixes for common prefixes/postfixes, and AutoMapper will match things up for you appropriately. These methods can be found on the Profile classes.

0

精彩评论

暂无评论...
验证码 换一张
取 消