Exemple #1
0
        /// <summary>
        /// Return the sequence of methods to call while building the target object.
        /// </summary>
        /// <param name="context">Current build context.</param>
        /// <param name="resolverPolicyDestination">The <see cref='IPolicyList'/> to add any
        /// generated resolver objects into.</param>
        /// <returns>Sequence of methods to call.</returns>
        public IEnumerable <SelectedMethod> SelectMethods(IBuilderContext context, IPolicyList resolverPolicyDestination)
        {
            foreach (Pair <MethodInfo, IEnumerable <InjectionParameterValue> > method in methods)
            {
                Type                   typeToBuild = context.BuildKey.Type;
                SelectedMethod         selectedMethod;
                ReflectionHelper       typeReflector   = new ReflectionHelper(method.First.DeclaringType);
                MethodReflectionHelper methodReflector = new MethodReflectionHelper(method.First);
                if (!methodReflector.MethodHasOpenGenericParameters && !typeReflector.IsOpenGeneric)
                {
                    selectedMethod = new SelectedMethod(method.First);
                }
                else
                {
                    Type[] closedMethodParameterTypes =
                        methodReflector.GetClosedParameterTypes(typeToBuild.GetTypeInfo().GenericTypeArguments);
                    selectedMethod = new SelectedMethod(
                        typeToBuild.GetMethodHierarchical(method.First.Name, closedMethodParameterTypes));
                }

                SpecifiedMemberSelectorHelper.AddParameterResolvers(
                    typeToBuild,
                    resolverPolicyDestination,
                    method.Second,
                    selectedMethod);
                yield return(selectedMethod);
            }
        }
Exemple #2
0
 /// <summary>
 /// Return the sequence of methods to call while building the target object.
 /// </summary>
 /// <param name="context">Current build context.</param>
 /// <returns>Sequence of methods to call.</returns>
 public IEnumerable <SelectedMethod> SelectMethods(IBuilderContext context)
 {
     foreach (Pair <MethodInfo, IEnumerable <InjectionParameterValue> > method in methods)
     {
         Type                   typeToBuild = BuildKey.GetType(context.BuildKey);
         SelectedMethod         selectedMethod;
         ReflectionHelper       typeReflector   = new ReflectionHelper(method.First.DeclaringType);
         MethodReflectionHelper methodReflector = new MethodReflectionHelper(method.First);
         if (!methodReflector.MethodHasOpenGenericParameters && !typeReflector.IsOpenGeneric)
         {
             selectedMethod = new SelectedMethod(method.First);
         }
         else
         {
             Type[] closedMethodParameterTypes =
                 methodReflector.GetClosedParameterTypes(typeToBuild.GetGenericArguments());
             selectedMethod = new SelectedMethod(
                 typeToBuild.GetMethod(method.First.Name, closedMethodParameterTypes));
         }
         SpecifiedMemberSelectorHelper.AddParameterResolvers(
             typeToBuild,
             context.PersistentPolicies,
             method.Second,
             selectedMethod);
         yield return(selectedMethod);
     }
 }
Exemple #3
0
        /// <summary>
        /// Choose the constructor to call for the given type.
        /// </summary>
        /// <param name="context">Current build context</param>
        /// <returns>The chosen constructor.</returns>
        public SelectedConstructor SelectConstructor(IBuilderContext context)
        {
            SelectedConstructor result;
            Type typeToBuild = BuildKey.GetType(context.BuildKey);

            ReflectionHelper typeReflector = new ReflectionHelper(ctor.DeclaringType);

            if (!ctorReflector.MethodHasOpenGenericParameters && !typeReflector.IsOpenGeneric)
            {
                result = new SelectedConstructor(ctor);
            }
            else
            {
                Type[] closedCtorParameterTypes =
                    ctorReflector.GetClosedParameterTypes(typeToBuild.GetGenericArguments());
                result = new SelectedConstructor(typeToBuild.GetConstructor(closedCtorParameterTypes));
            }

            SpecifiedMemberSelectorHelper.AddParameterResolvers(typeToBuild, context.PersistentPolicies, parameterValues, result);
            return(result);
        }
Exemple #4
0
        public SelectedConstructor SelectConstructor(IBuilderContext context, IPolicyList resolverPolicyDestination)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(context, "context");

            SelectedConstructor result;
            Type typeToBuild = context.BuildKey.Type;

            ReflectionHelper typeReflector = new ReflectionHelper(ctor.DeclaringType);

            if (!ctorReflector.MethodHasOpenGenericParameters && !typeReflector.IsOpenGeneric)
            {
                result = new SelectedConstructor(ctor);
            }
            else
            {
                Type[] closedCtorParameterTypes =
                    ctorReflector.GetClosedParameterTypes(typeToBuild.GenericTypeArguments);
                result = new SelectedConstructor(typeToBuild.GetConstructorInfo(closedCtorParameterTypes));
            }

            SpecifiedMemberSelectorHelper.AddParameterResolvers(typeToBuild, resolverPolicyDestination, parameterValues, result);
            return(result);
        }