当前位置: 首页>>代码示例>>C#>>正文


C# ProxyGenerator.CreateClassProxyWithTarget方法代码示例

本文整理汇总了C#中Castle.DynamicProxy.ProxyGenerator.CreateClassProxyWithTarget方法的典型用法代码示例。如果您正苦于以下问题:C# ProxyGenerator.CreateClassProxyWithTarget方法的具体用法?C# ProxyGenerator.CreateClassProxyWithTarget怎么用?C# ProxyGenerator.CreateClassProxyWithTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Castle.DynamicProxy.ProxyGenerator的用法示例。


在下文中一共展示了ProxyGenerator.CreateClassProxyWithTarget方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildProxy

        public override object BuildProxy(ProxyGenerator generator, Type objType, CommonData data, object baseObj)
        {
            object proxy;
            if (baseObj == null)
            {
                proxy = generator.CreateClassProxyWithTarget(objType,
                    new ProxyGenerationOptions(new GeneralProxyGenerationHook())
                    {
                        Selector = _redisObjectSelector
                    },
                    new GeneralGetInterceptor(data), new RedisObjectSetInterceptor(data));
            }
            else
            {
                proxy = generator.CreateClassProxyWithTarget(objType, baseObj,
                    new ProxyGenerationOptions(new GeneralProxyGenerationHook())
                    {
                        Selector = _redisObjectSelector
                    },
                    new GeneralGetInterceptor(data), new RedisObjectSetInterceptor(data));
            }

            return proxy;
        }
开发者ID:DemgelOpenSource,项目名称:DemgelRedis,代码行数:24,代码来源:RedisObjectHandler.cs

示例2: Main

        public static void Main(string[] args)
        {
            // Add Console.Out as a listener for Debug.WriteLine to show in Mono
            Debug.Listeners.Add( new ConsoleTraceListener(useErrorStream: false) );

            // Using dependency injection to specify output stream
            // i.e. Foo proxies ILogger
            ILogger logger = new Logger (Console.Out);
            Foo foo = new Foo (logger);
            foo.Write ("Testing Foo\n");

            Console.WriteLine("Hard-coded proxy object demonstrating trace logging:");
            // You could create a second foo type which appears to be IFoo
            // but actually traces method enter/exit by proxy
            IFoo foo2 = new FooInterfaceProxy (logger);
            foo2.Write ("Testing FooInterfaceProxy #1");
            foo2.Write ("Testing FooInterfaceProxy #2");

            Console.WriteLine("Hard-coded proxy object demonstrating added functionality:");
            IFoo foo3 = new FooClassProxy(logger);
            foo3.Write("Testing FooClassProxy");

            Console.WriteLine("Dynamically proxy an existing object's virtual members (any object works):");
            var proxify = new ProxyGenerator();
            var interceptors = new IInterceptor[] { new DebugLogger() };
            Foo foo4 = proxify.CreateClassProxyWithTarget(foo, interceptors);
            foo4.Write("Class Foo proxied dynamically using CreateClassProxyWithTarget");
            Console.WriteLine("Calling Class Foo's ToString(): {0}", foo4.ToString());
            Console.WriteLine("Calling IFoo.ShowBar(): {0}", foo4.ShowBar());
            Console.WriteLine("Calling Foo.ShowBaz(): {0}\n", foo4.ShowBaz());

            Console.WriteLine ("Dynamic Proxy a specific target:");
            IFoo foo5 = (IFoo)proxify.CreateInterfaceProxyWithTarget(typeof(IFoo), foo, interceptors);
            foo5.Write("Class Foo proxied dynamically using CreateInterfaceProxyWithTarget");
            Console.WriteLine("Calling Class Foo's ToString(): {0}\n", foo5.ToString());
            Console.WriteLine("Calling IFoo.ShowBar(): {0}", foo5.ShowBar());
            Console.WriteLine("Notice the order of interception above.");
        }
开发者ID:tjmukurumbira,项目名称:blogs,代码行数:38,代码来源:Main.cs

示例3: CastleTestSealedClass

        public void CastleTestSealedClass()
        {
            var proxyGenerator = new ProxyGenerator();

            var originalObj = new SealedSpecialDisposable();

            Assert.Throws<TypeLoadException>(() => proxyGenerator.CreateClassProxyWithTarget(originalObj, Enumerable.Empty<IInterceptor>().ToArray()));
        }
开发者ID:GProulx,项目名称:Glimpse,代码行数:8,代码来源:CastleShould.cs

示例4: CastleTestClass1

        public void CastleTestClass1()
        {
            var proxyGenerator = new ProxyGenerator();

            var originalObj = new SimpleSpecialDisposable();

            var newObj = proxyGenerator.CreateClassProxyWithTarget(originalObj, Enumerable.Empty<IInterceptor>().ToArray());

            Assert.IsAssignableFrom<IDisposable>(newObj);
            Assert.IsAssignableFrom<ISpecialDisposable>(newObj);
            Assert.IsAssignableFrom<SimpleSpecialDisposable>(newObj);
        }
开发者ID:GProulx,项目名称:Glimpse,代码行数:12,代码来源:CastleShould.cs

示例5: CastleTestReallyCrazyConstructorClass

        public void CastleTestReallyCrazyConstructorClass()
        {
            var proxyGenerator = new ProxyGenerator();

            var originalObj = new ReallyCrazyConstructorSpecialDisposable("3");

            Assert.Throws<InvalidProxyConstructorArgumentsException>(
                () => proxyGenerator.CreateClassProxyWithTarget(originalObj.GetType(), originalObj, new object[] { "a", "b" }, Enumerable.Empty<IInterceptor>().ToArray()));
        }
开发者ID:GProulx,项目名称:Glimpse,代码行数:9,代码来源:CastleShould.cs

示例6: CastleTestConstructorClass

        public void CastleTestConstructorClass()
        {
            var proxyGenerator = new ProxyGenerator();

            var originalObj = new CrazyConstructorSpecialDisposable("test", "test2");

            var newObj = (CrazyConstructorSpecialDisposable)proxyGenerator.CreateClassProxyWithTarget(originalObj.GetType(), originalObj, new object[] { "a", "b" }, Enumerable.Empty<IInterceptor>().ToArray());

            Assert.IsAssignableFrom<IDisposable>(newObj);
            Assert.IsAssignableFrom<ISpecialDisposable>(newObj);
            Assert.IsAssignableFrom<CrazyConstructorSpecialDisposable>(newObj);
            Assert.Equal("a", newObj.A);
            Assert.Equal("b", newObj.B);
        }
开发者ID:GProulx,项目名称:Glimpse,代码行数:14,代码来源:CastleShould.cs

示例7: Decorate

        /// <summary>
        /// Decoration request
        /// </summary>
        /// <param name="context">Context info</param>
        /// <remarks>do not have to decorate, but may if it wants to. sorta..</remarks>
        public void Decorate(DecoratorContext context)
        {
            if (!CanDecorate(context))
                return;

            var options = new ProxyGenerationOptions();

            var services = context.Services;
            if (IgnoreClassAsService && services.Length > 1)
                services = services.Where(x => !x.IsClass).ToArray();

            var generator = new ProxyGenerator();
            if (services.Any(x => x.IsClass))
            {
                if (services.Length > 1)
                    throw new InvalidOperationException(
                        "A class that register itself as a service may not also be registered with interfaces. See the remarks in the IgnoreClassAsService property.");

                var clazz = context.Services.Single(x => x.IsClass);
                context.Instance = generator.CreateClassProxyWithTarget(clazz, context.Instance,
                                                                        CreateInterceptor(context));
            }
            else
            {
                var others = services.Where(x => x.IsInterface).Skip(1);
                var first = services.First();
                context.Instance = generator.CreateInterfaceProxyWithTarget
                    (first, others.ToArray(), context.Instance,
                     CreateInterceptor(context));
            }

        }
开发者ID:hallco978,项目名称:Griffin.Container,代码行数:37,代码来源:CastleDecorator.cs

示例8: CreateProxyFor

 public static object CreateProxyFor(Type type, IDictionary<string, object> data)
 {
     var generator = new ProxyGenerator();
     return generator.CreateClassProxyWithTarget(type, Activator.CreateInstance(type), new DataInterceptor(data));
 }
开发者ID:dkschlos,项目名称:PVM.NET,代码行数:5,代码来源:DataMapper.cs


注:本文中的Castle.DynamicProxy.ProxyGenerator.CreateClassProxyWithTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。