Last active
November 7, 2022 10:48
-
-
Save OsamaShabrez/8077568767fc331713f2dad3155477e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/AutoMapper/AutoMapper/issues/3834 | |
public static class AutoMapperExtensions | |
{ | |
public static IMappingExpression<TSource, TDestination> MapRecordMember<TSource, TDestination, TMember>( | |
this IMappingExpression<TSource, TDestination> mappingExpression, | |
Expression<Func<TDestination, TMember>> destinationMember, Expression<Func<TSource, TMember>> sourceMember) | |
{ | |
var memberInfo = ReflectionHelper.FindProperty(destinationMember); | |
string memberName = memberInfo.Name; | |
return mappingExpression | |
.ForMember(destinationMember, opt => opt.MapFrom(sourceMember)) | |
.ForCtorParam(memberName, opt => opt.MapFrom(sourceMember)); | |
} | |
} | |
// usage | |
CreateMap<src, dest>() | |
.MapRecordMember(dest => dest.ExtraId, src => src.DbExtraId) | |
.ReverseMap(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment