Ejemplo n.º 1
0
        private static ContainerConstructorInfo GetNonAttributedConstructor(Type source, Type[] parameterTypes, IEnumerable <ConstructorInfo> constructors)
        {
            ContainerConstructorInfo result = null;

            foreach (var constructor in constructors)
            {
                var parametersInfo = CanUseParameters(constructor, parameterTypes);
                if (parametersInfo != null)
                {
                    if (result != null)
                    {
                        throw new AmbiguousConstructorException(source);
                    }
                    result = new ContainerConstructorInfo
                    {
                        ConstructorInfo = constructor,
                        ParametersInfo  = parametersInfo
                    };
                }
            }
            if (result == null)
            {
                throw new NoConstructorException(source);
            }
            return(result);
        }
Ejemplo n.º 2
0
        private static ContainerConstructorInfo TryGetAttributedConstructor(Type source, Type[] parameterTypes,
                                                                            IEnumerable <ConstructorInfo> constructors)
        {
            ContainerConstructorInfo      result                 = null;
            HashSet <Type>                parameterTypesSet      = GetParameterTypesSet(parameterTypes);
            IEnumerable <ConstructorInfo> attributedConstructors =
                constructors.Where(info => info.IsDefined(typeof(ContainerConstructorAttribute), false));
            bool hasContainerConstructors = false;

            foreach (ConstructorInfo constructor in attributedConstructors)
            {
                hasContainerConstructors = true;
                HashSet <Type> constructorTypesSet = GetConstructorTypesSet(constructor);
                if (parameterTypesSet.SetEquals(constructorTypesSet))
                {
                    int[] parametersInfo = CanUseParameters(constructor, parameterTypes);
                    if (parametersInfo == null)
                    {
                        throw new BadContainerConstructorAttributeException(constructor);
                    }
                    if (result != null)
                    {
                        throw new AmbiguousConstructorException(source);
                    }
                    result = new ContainerConstructorInfo
                    {
                        ConstructorInfo = constructor,
                        ParametersInfo  = parametersInfo
                    };
                }
            }
            if (hasContainerConstructors && result == null)
            {
                throw new NoConstructorException(source);
            }
            return(result);
        }
Ejemplo n.º 3
0
 public IClassFactory BuildFactory(ContainerConstructorInfo constructorInfo, Type wrapperType)
 {
     return(new ClassFactory(EmitConstruct(constructorInfo.ConstructorInfo, constructorInfo.ParametersInfo, wrapperType), constructorInfo.ConstructorInfo.ReflectedType));
 }
Ejemplo n.º 4
0
 public Func <IInternalContainer, IInjectionContext, object[], object> BuildConstructionDelegate(ContainerConstructorInfo constructorInfo, Type wrapperType)
 {
     return(EmitConstruct(constructorInfo.ConstructorInfo, constructorInfo.ParametersInfo, wrapperType));
 }