Ejemplo n.º 1
0
        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo,
                                                IProfileConfiguration options)
        {
            var parameters     = new List <ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
            {
                return(false);
            }

            foreach (var parameter in ctorParameters)
            {
                var members = new LinkedList <MemberInfo>();

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, parameter.GetType(),
                                                                parameter.Name, members);

                var resolvers = members.Select(mi => ReflectionHelper.ToMemberGetter(mi));

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve);

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return(true);
        }
Ejemplo n.º 2
0
        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo,
            IProfileConfiguration options)
        {
            var parameters = new List<ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            foreach (var parameter in ctorParameters)
            {
                var members = new LinkedList<MemberInfo>();

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, parameter.GetType(),
                    parameter.Name, members);

                var resolvers = members.Select(mi => ReflectionHelper.ToMemberGetter(mi));

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve);

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return true;
        }
 public CtorParamConfigurationExpression(ConstructorParameterMap ctorParamMap)
 {
     _ctorParamMap = ctorParamMap;
 }