Пример #1
0
        public IPropertyMapConfiguration Reverse()
        {
            var destinationType = DestinationMember.DeclaringType;

            if (_sourceMembers != null)
            {
                if (_sourceMembers.Length > 1)
                {
                    return(null);
                }
                var reversedMemberConfiguration = new MemberConfigurationExpression <
                    TDestination,
                    TSource,
                    object
                    >(_sourceMembers[0], destinationType);
                reversedMemberConfiguration.MapFrom(DestinationMember.Name);
                return(reversedMemberConfiguration);
            }
            if (destinationType.IsGenericTypeDefinition) // .ForMember("InnerSource", o => o.MapFrom(s => s))
            {
                return(null);
            }
            return(PathConfigurationExpression <TDestination, TSource, object> .Create(
                       SourceExpression,
                       GetDestinationExpression()
                       ));
        }
Пример #2
0
        internal static IPropertyMapConfiguration Create(
            LambdaExpression destination,
            LambdaExpression source
            )
        {
            if (destination == null || !destination.IsMemberPath(out var chain))
            {
                return(null);
            }
            var reversed = new PathConfigurationExpression <TSource, TDestination, object>(
                destination,
                chain
                );

            if (reversed.MemberPath.Length == 1)
            {
                var reversedMemberExpression = new MemberConfigurationExpression <
                    TSource,
                    TDestination,
                    object
                    >(reversed.DestinationMember, typeof(TSource));
                reversedMemberExpression.MapFromUntyped(source);
                return(reversedMemberExpression);
            }
            reversed.MapFromUntyped(source);
            return(reversed);
        }
Пример #3
0
        internal MemberConfigurationExpression ForMember(MemberInfo destinationProperty, Action <IMemberConfigurationExpression> memberOptions)
        {
            var expression = new MemberConfigurationExpression(destinationProperty, Types.SourceType);

            MemberConfigurations.Add(expression);

            memberOptions(expression);

            return(expression);
        }