AUtomapper - custom property mapping
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.
精彩评论