public IMemberConfiguration <T, TN> Member <TMember, TNMember>(Expression <Func <TN, TNMember> > dest, Expression <Func <T, TMember> > src)
        {
            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }

            var memberExpression = dest.Body as MemberExpression;

            if (memberExpression == null)
            {
                throw new Exception("MemberExpression should return one of the properties of destination class");
            }

            var propertyInfo = typeof(TN).GetProperty(memberExpression.Member.Name);

            if (propertyInfo.CanWrite && propertyInfo.GetSetMethod(true).IsPublic)
            {
                _typeMapper.MapMember(dest, src);
            }
            return(this);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Skip specified convention member mapping and use a custom function to map to the target member.
 /// </summary>
 /// <typeparam name="TSource">The source type.</typeparam>
 /// <typeparam name="TTarget">The target type.</typeparam>
 /// <typeparam name="TSourceMember">The type of the member to map to of the source.</typeparam>
 /// <typeparam name="TTargetMember">The type of the member to map to of the target.</typeparam>
 /// <param name="typeMapper">The type mapping strategy.</param>
 /// <param name="targetMember">The expression of the target member to map to.</param>
 /// <param name="expression">Callback to map from source type to the target member</param>
 /// <returns>The type mapping strategy.</returns>
 public static ITypeMapper <TSource, TTarget> MapMember <TSource, TTarget, TSourceMember, TTargetMember>(
     this ITypeMapper <TSource, TTarget> typeMapper, Expression <Func <TTarget, TSourceMember> > targetMember,
     Func <TSource, TTargetMember> expression)
 {
     return(typeMapper.MapMember(ExtractMember(targetMember).Member.Name, expression));
 }