Beispiel #1
0
        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, ProfileMap options)
        {
            var ctorParameters = destCtor.GetParameters();

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

            var ctorMap = new ConstructorMap(destCtor, typeMap);

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

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, destCtor.DeclaringType, parameter.GetType(), parameter.Name, resolvers);
                if (!canResolve && parameter.IsOptional)
                {
                    canResolve = true;
                }
                ctorMap.AddParameter(parameter, resolvers.ToArray(), canResolve);
            }

            typeMap.ConstructorMap = ctorMap;

            return(ctorMap.CanResolve);
        }