Exemplo n.º 1
0
        public void ShoulInterceptOnlyPrivateMethod()
        {
            var privateMethodName = ObjectProxyHelper.GetMethodNames <IPrivateMethod>(i => i.SaveChanges())[0];

            var proxy = ObjectProxyFactory
                        .Configure <IPrivateMethod>(new DbFileContext()) //initialize fluent config, with given interface and instance
                        .FilterMethods(privateMethodName)                //only intercept methods with the given name
                        .AddPreDecoration(ctx =>
            {
                Debug.Assert(ctx.CallCtx.MethodName == privateMethodName);
                Console.Write("Saving Changes");
            })
                        .AddPostDecoration(ctx =>
            {
                Console.Write("Saved Changes");
                Debug.Assert(ctx.CallCtx.MethodName == privateMethodName);
            })
                                        //.SetParameters(new object())
                        .CreateProxy(); //finally create and return the proxy


            proxy.SaveChanges();
        }
Exemplo n.º 2
0
        public void RunLoopProxyfied()
        {
            var dbContext = new DbFileContext();

            var privateMethodName = ObjectProxyHelper.GetMethodNames <IPrivateMethod>(j => j.SaveChanges())[0];


            var proxy = ObjectProxyFactory
                        .Configure <IPrivateMethod>(dbContext) //initialize fluent config, with given interface and instance
                        .FilterMethods(privateMethodName)      //only intercept methods with the given name
                        .CreateProxy();                        //finally create and return the proxy

            var sw = Stopwatch.StartNew();

            for (int i = 0; i < 1000; i++)
            {
                int i1 = i;
                Console.Write(i1);
                proxy.SaveChanges();
            }

            Console.WriteLine("took {0}", sw.Elapsed.ToString("g"));
            Console.ReadLine();
        }