public void KeysForDifferentMethodsAreNotEqual() { var key1 = HandlerPipelineKey.ForMethod(StaticReflection.GetMethodInfo <Base>(b => b.Method1())); var key2 = HandlerPipelineKey.ForMethod(StaticReflection.GetMethodInfo <Base>(b => b.Method2())); Assert.AreNotEqual(key1, key2); }
public void KeysForSameMethodReflectedFromDifferentTypesOnDifferentModulesAreEqual() { var key1 = HandlerPipelineKey.ForMethod(StaticReflection.GetMethodInfo <object>(o => o.ToString())); var key2 = HandlerPipelineKey.ForMethod(StaticReflection.GetMethodInfo <Derived>(b => b.ToString())); Assert.AreEqual(key1, key2); }
public void KeysForSameMethodReflectedFromDifferentTypesAreEqual() { var key1 = HandlerPipelineKey.ForMethod(StaticReflection.GetMethodInfo <Base>(b => b.Method2())); var key2 = HandlerPipelineKey.ForMethod(StaticReflection.GetMethodInfo <Derived>(b => b.Method2())); Assert.AreEqual(key1, key2); }
public void KeysForOverridenMethodReflectedFromDifferentTypesAreNotEqual() { // using plain reflection - lambdas get optimized so we cannot get the override through them var key1 = HandlerPipelineKey.ForMethod(typeof(Base).GetMethod("Method1")); var key2 = HandlerPipelineKey.ForMethod(typeof(Derived).GetMethod("Method1")); Assert.AreNotEqual(key1, key2); }
/// <summary> /// Retrieve the pipeline associated with the requested <paramref name="method"/>. /// </summary> /// <param name="method">The method for which the pipeline is being requested.</param> /// <returns>The handler pipeline for the given method. If no pipeline has /// been set, returns a new empty pipeline.</returns> public HandlerPipeline GetPipeline(MethodBase method) { HandlerPipelineKey key = HandlerPipelineKey.ForMethod(method); HandlerPipeline pipeline = EmptyPipeline; if (_pipelines.ContainsKey(key)) { pipeline = _pipelines[key]; } return(pipeline); }
/// <summary> /// GetOrDefault 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) { Guard.ArgumentNotNull(method, "method"); var pipeline = CreatePipeline(method.ImplementationMethodInfo, handlers); if (method.InterfaceMethodInfo != null) { _pipelines[HandlerPipelineKey.ForMethod(method.InterfaceMethodInfo)] = pipeline; } return(pipeline.Count > 0); }
private HandlerPipeline CreatePipeline(MethodInfo method, IEnumerable <ICallHandler> handlers) { HandlerPipelineKey key = HandlerPipelineKey.ForMethod(method); if (_pipelines.ContainsKey(key)) { return(_pipelines[key]); } if (method.GetBaseDefinition() == method) { _pipelines[key] = new HandlerPipeline(handlers); return(_pipelines[key]); } var basePipeline = CreatePipeline(method.GetBaseDefinition(), handlers); _pipelines[key] = basePipeline; return(basePipeline); }
/// <summary> /// Set a new pipeline for a method. /// </summary> /// <param name="method">The method on which the pipeline should be set.</param> /// <param name="pipeline">The new pipeline.</param> public void SetPipeline(MethodBase method, HandlerPipeline pipeline) { HandlerPipelineKey key = HandlerPipelineKey.ForMethod(method); _pipelines[key] = pipeline; }