static void DynamicInterceptorWithRegistry(object instance)
        {
            var interceptor = new DynamicInterceptor();
            var registry    = new RegistryInterceptionHandler();

            registry.Register <IMyType>(x => x.MyProperty, new MyHandler());
            registry.Register <IMyType>(x => x.MyMethod(), new MyHandler());
            dynamic myProxy = interceptor.Intercept(instance, null, registry);

            myProxy.MyMethod();
        }
        static void DynamicInterceptor(object instance)
        {
            //Dynamic interceptor
            var     interceptor      = new DynamicInterceptor();
            var     canIntercept     = interceptor.CanIntercept(instance);
            dynamic myProxy          = interceptor.Intercept(instance, null, new MyHandler());
            var     proxy            = myProxy as IInterceptionProxy;
            var     otherInterceptor = proxy.Interceptor;
            int     result           = myProxy.MyMethod();

            Assert.AreEqual(20, result);
        }
Ejemplo n.º 3
0
        public void CanDoDynamicInterceptionWithRegistry()
        {
            //interception through a registry
            var instance    = new MyType3();
            var interceptor = new DynamicInterceptor();
            var registry    = new RegistryInterceptionHandler()
                              .Register <MyType3>(x => x.MyProperty, new ModifyResultHandler())
                              .Register <MyType3>(x => x.MyMethod(), new ModifyResultHandler());
            dynamic myProxy = interceptor.Intercept(instance, typeof(IMyType), registry);
            var     result  = myProxy.MyMethod();

            Assert.Equal(20, result);
        }
		static void DynamicInterceptor(object instance)
		{
			//Dynamic interceptor
			var interceptor = new DynamicInterceptor();
			var canIntercept = interceptor.CanIntercept(instance);
			dynamic myProxy = interceptor.Intercept(instance, null, new MyHandler());
			var proxy = myProxy as IInterceptionProxy;
			var otherInterceptor = proxy.Interceptor;
			int result = myProxy.MyMethod();
			Assert.AreEqual(20, result);
		}
		static void DynamicInterceptorWithRegistry(object instance)
		{
			var interceptor = new DynamicInterceptor();
			var registry = new RegistryInterceptionHandler();
			registry.Register<IMyType>(x => x.MyProperty, new MyHandler());
			registry.Register<IMyType>(x => x.MyMethod(), new MyHandler());
			dynamic myProxy = interceptor.Intercept(instance, null, registry);
			myProxy.MyMethod();
		}