Exemplo n.º 1
0
        public void CanDoDynamicInterceptionWithAttributes()
        {
            //interception through attributes
            var     instance = new MyType3();
            dynamic myProxy  = DynamicInterceptor.Instance.InterceptWithAttributes(instance);
            var     result   = myProxy.MyMethod();

            Assert.Equal(20, result);
        }
Exemplo n.º 2
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);
        }