Esempio n. 1
0
        private bool DoesNotHaveNoPoliciesAttributeRule(MethodImplementationInfo method)
        {
            bool doesNotHaveRule = true;

            doesNotHaveRule &= method.InterfaceMethodInfo != null?doesNotHaveNoPoliciesAttributeRule.Matches(method.InterfaceMethodInfo) : true;

            doesNotHaveRule &= doesNotHaveNoPoliciesAttributeRule.Matches(method.ImplementationMethodInfo);
            return(doesNotHaveRule);
        }
Esempio n. 2
0
 /// <summary>
 /// Return ordered collection of handlers in order that apply to the given member.
 /// </summary>
 /// <param name="member">Member that may or may not be assigned handlers by this policy.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Collection of handlers (possibly empty) that apply to this member.</returns>
 protected override IEnumerable <ICallHandler> DoGetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     if (this.Matches(member))
     {
         foreach (string callHandlerName in this.callHandlerNames)
         {
             yield return(container.Resolve <ICallHandler>(callHandlerName));
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Checks if the rules in this policy match the given member info.
        /// </summary>
        /// <param name="member">MemberInfo to check against.</param>
        /// <returns>true if ruleset matches, false if it does not.</returns>
        protected override bool DoesMatch(MethodImplementationInfo member)
        {
            Unity.Utility.Guard.ArgumentNotNull(member, "member");

            bool matchesInterface = member.InterfaceMethodInfo != null?this.ruleSet.Matches(member.InterfaceMethodInfo) : false;

            bool matchesImplementation = this.ruleSet.Matches(member.ImplementationMethodInfo);

            return(matchesInterface | matchesImplementation);
        }
Esempio n. 4
0
 /// <summary>
 /// Gets the policies in the <see cref="PolicySet"/> that do not
 /// apply to the given member.
 /// </summary>
 /// <param name="member">Member to check.</param>
 /// <returns>Collection of policies that do not apply to <paramref name="member"/>.</returns>
 public IEnumerable <InjectionPolicy> GetPoliciesNotFor(MethodImplementationInfo member)
 {
     foreach (InjectionPolicy policy in this)
     {
         if (!policy.Matches(member))
         {
             yield return(policy);
         }
     }
 }
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
        /// </summary>
        /// <returns>
        /// true if the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />; otherwise, false.
        /// </returns>
        /// <param name="obj">The <see cref="T:System.Object" /> to compare with the current <see cref="T:System.Object" />. </param>
        /// <exception cref="T:System.NullReferenceException">The <paramref name="obj" /> parameter is null.</exception>
        /// <filterpriority>2</filterpriority>
        public override bool Equals(object obj)
        {
            MethodImplementationInfo other = obj as MethodImplementationInfo;

            if (obj == null || other == null)
            {
                return(false);
            }

            return(this == other);
        }
Esempio n. 6
0
        /// <summary>
        /// Get the pipeline for the given method, creating it if necessary.
        /// </summary>
        /// <param name="method">Method to retrieve the pipeline for.</param>
        /// <param name="handlers">Handlers to initialize the pipeline with</param>
        /// <returns>True if the pipeline has any handlers in it, false if not.</returns>
        public bool InitializePipeline(MethodImplementationInfo method, IEnumerable <ICallHandler> handlers)
        {
            Unity.Utility.Guard.ArgumentNotNull(method, "method");

            var pipeline = CreatePipeline(method.ImplementationMethodInfo, handlers);

            if (method.InterfaceMethodInfo != null)
            {
                pipelines[HandlerPipelineKey.ForMethod(method.InterfaceMethodInfo)] = pipeline;
            }

            return(pipeline.Count > 0);
        }
Esempio n. 7
0
 /// <summary>
 /// Derived classes implement this method to supply the list of handlers for
 /// this specific member.
 /// </summary>
 /// <param name="member">Member to get handlers for.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Enumerable collection of handlers for this method.</returns>
 protected override IEnumerable <ICallHandler> DoGetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     if (member.InterfaceMethodInfo != null)
     {
         foreach (HandlerAttribute attr in ReflectionHelper.GetAllAttributes <HandlerAttribute>(member.InterfaceMethodInfo, true))
         {
             yield return(attr.CreateHandler(container));
         }
     }
     foreach (HandlerAttribute attr in ReflectionHelper.GetAllAttributes <HandlerAttribute>(member.ImplementationMethodInfo, true))
     {
         yield return(attr.CreateHandler(container));
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Returns ordered collection of handlers in order that apply to the given member.
 /// </summary>
 /// <param name="member">Member that may or may not be assigned handlers by this policy.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Collection of handlers (possibly empty) that apply to this member.</returns>
 public virtual IEnumerable <ICallHandler> GetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     if (DoesNotHaveNoPoliciesAttributeRule(member))
     {
         List <ICallHandler> handlers = new List <ICallHandler>(DoGetHandlersFor(member, container));
         if (handlers.Count > 0)
         {
             foreach (ICallHandler handler in handlers)
             {
                 yield return(handler);
             }
             yield break;
         }
     }
 }
Esempio n. 9
0
        internal static IEnumerable <ICallHandler> CalculateHandlersFor(
            IEnumerable <InjectionPolicy> policies,
            MethodImplementationInfo member,
            IUnityContainer container)
        {
            List <ICallHandler> ordered    = new List <ICallHandler>();
            List <ICallHandler> nonOrdered = new List <ICallHandler>();

            foreach (InjectionPolicy p in policies)
            {
                foreach (ICallHandler handler in p.GetHandlersFor(member, container))
                {
                    if (handler.Order != 0)
                    {
                        bool inserted = false;
                        // add in order to ordered
                        for (int i = ordered.Count - 1; i >= 0; i--)
                        {
                            if (ordered[i].Order <= handler.Order)
                            {
                                ordered.Insert(i + 1, handler);
                                inserted = true;
                                break;
                            }
                        }
                        if (!inserted)
                        {
                            ordered.Insert(0, handler);
                        }
                    }
                    else
                    {
                        nonOrdered.Add(handler);
                    }
                }
            }
            ordered.AddRange(nonOrdered);
            return(ordered);
        }
Esempio n. 10
0
 /// <summary>
 /// Checks if the rules in this policy match the given member info.
 /// </summary>
 /// <param name="member">MemberInfo to check against.</param>
 /// <returns>true if ruleset matches, false if it does not.</returns>
 public bool Matches(MethodImplementationInfo member)
 {
     return(DoesNotHaveNoPoliciesAttributeRule(member) &&
            DoesMatch(member));
 }
Esempio n. 11
0
 /// <summary>
 /// Derived classes implement this method to supply the list of handlers for
 /// this specific member.
 /// </summary>
 /// <param name="member">Member to get handlers for.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Enumerable collection of handlers for this method.</returns>
 protected abstract IEnumerable <ICallHandler> DoGetHandlersFor(MethodImplementationInfo member, IUnityContainer container);
Esempio n. 12
0
 /// <summary>
 /// Derived classes implement this method to calculate if the policy
 /// will provide any handler to the specified member.
 /// </summary>
 /// <param name="member">Member to check.</param>
 /// <returns>true if policy applies to this member, false if not.</returns>
 protected abstract bool DoesMatch(MethodImplementationInfo member);
Esempio n. 13
0
 /// <summary>
 /// Gets the handlers that apply to the given member based on all policies in the <see cref="PolicySet"/>.
 /// </summary>
 /// <param name="member">Member to get handlers for.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Collection of call handlers for <paramref name="member"/>.</returns>
 public IEnumerable <ICallHandler> GetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     return(new List <ICallHandler>(CalculateHandlersFor(this, member, container)));
 }