/// <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 override bool DoesMatch(MethodImplementationInfo member) { bool matchesInterface = member.InterfaceMethodInfo != null ? attributeMatchRule.Matches(member.InterfaceMethodInfo) : false; bool matchesImplementation = attributeMatchRule.Matches(member.ImplementationMethodInfo); return matchesInterface | matchesImplementation; }
private bool DoesNotHaveNoPoliciesAttributeRule(MethodImplementationInfo method) { bool doesNotHaveRule = true; doesNotHaveRule &= method.InterfaceMethodInfo != null ? doesNotHaveNoPoliciesAttributeRule.Matches(method.InterfaceMethodInfo) : true; doesNotHaveRule &= doesNotHaveNoPoliciesAttributeRule.Matches(method.ImplementationMethodInfo); return doesNotHaveRule; }
protected override bool DoesMatch(MethodImplementationInfo member) { Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(member, "member"); bool matchesInterface = member.InterfaceMethodInfo != null && this.ruleSet.Matches(member.InterfaceMethodInfo); bool matchesImplementation = this.ruleSet.Matches(member.ImplementationMethodInfo); return matchesInterface | matchesImplementation; }
/// <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 override bool DoesMatch(MethodImplementationInfo member) { bool matchesInterface = member.InterfaceMethodInfo != null?attributeMatchRule.Matches(member.InterfaceMethodInfo) : false; bool matchesImplementation = attributeMatchRule.Matches(member.ImplementationMethodInfo); return(matchesInterface | matchesImplementation); }
private bool DoesNotHaveNoPoliciesAttributeRule(MethodImplementationInfo method) { bool doesNotHaveRule = true; doesNotHaveRule &= method.InterfaceMethodInfo != null?doesNotHaveNoPoliciesAttributeRule.Matches(method.InterfaceMethodInfo) : true; doesNotHaveRule &= doesNotHaveNoPoliciesAttributeRule.Matches(method.ImplementationMethodInfo); return(doesNotHaveRule); }
protected override bool DoesMatch(MethodImplementationInfo member) { Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(member, "member"); bool matchesInterface = member.InterfaceMethodInfo != null?this.attributeMatchRule.Matches(member.InterfaceMethodInfo) : false; bool matchesImplementation = this.attributeMatchRule.Matches(member.ImplementationMethodInfo); return(matchesInterface | matchesImplementation); }
/// <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)); } } }
/// <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) { var pipeline = CreatePipeline(method.ImplementationMethodInfo, handlers); if(method.InterfaceMethodInfo != null) { pipelines[HandlerPipelineKey.ForMethod(method.InterfaceMethodInfo)] = pipeline; } return pipeline.Count > 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); } } }
/// <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> /// 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) { var pipeline = CreatePipeline(method.ImplementationMethodInfo, handlers); if (method.InterfaceMethodInfo != null) { pipelines[HandlerPipelineKey.ForMethod(method.InterfaceMethodInfo)] = pipeline; } return(pipeline.Count > 0); }
/// <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); }
public bool InitializePipeline(MethodImplementationInfo method, IEnumerable<ICallHandler> handlers) { Microsoft.Practices.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; }
public bool InitializePipeline(MethodImplementationInfo method, IEnumerable <ICallHandler> handlers) { Microsoft.Practices.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); }
/// <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); } }
/// <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)); } }
/// <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; } } }
public void WhenConfiguredContainer_ThenCanResolvePolicy() { using (var container = new UnityContainer()) { this.policyData.ConfigureContainer(container); var policy = container.Resolve<RuleDrivenPolicy>("policy"); var method = new MethodImplementationInfo(StaticReflection.GetMethodInfo<object>(o => o.ToString()), StaticReflection.GetMethodInfo<object>(o => o.ToString())); Assert.AreEqual("policy", policy.Name); Assert.IsFalse(policy.Matches(method)); Assert.AreEqual(0, policy.GetHandlersFor(method, container).Count()); } }
/// <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; } } }
public void WhenConfiguredContainer_ThenCanResolvePolicy() { using (var container = new UnityContainer()) { this.policyData.ConfigureContainer(container); var policy = container.Resolve<RuleDrivenPolicy>("policy"); var method = new MethodImplementationInfo(StaticReflection.GetMethodInfo<object>(o => o.ToString()), StaticReflection.GetMethodInfo<object>(o => o.ToString())); Assert.AreEqual("policy", policy.Name); Assert.IsTrue(policy.Matches(method)); Assert.AreEqual(0, policy.GetHandlersFor(method, container).Count()); Assert.AreNotSame(policy, container.Resolve<RuleDrivenPolicy>("policy")); Assert.IsTrue(container.Registrations.Any(r => r.Name == "type-policy" && r.RegisteredType == typeof(IMatchingRule) && r.MappedToType == typeof(TypeMatchingRule))); } }
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); }
/// <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)); }
/// <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);
/// <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);
/// <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); }
/// <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);
/// <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))); }
public MethodInfo MethodInfoForPipeline(MethodImplementationInfo methodInfo) { Guard.ArgumentNotNull(methodInfo, "methodInfo"); return(methodInfo.ImplementationMethodInfo); }