动态代理的5模式使用示例和Mixin模式(2)

foreach (var interfaceType in animal.GetType().GetInterfaces())
                {
                    Console.WriteLine(interfaceType);
                }
            }



动态代理的5模式使用示例和Mixin模式

第三种:InterfaceProxyWithoutTarget

复制代码 代码如下:


{
                Console.WriteLine("\n*************InterfaceProxyWithoutTarget*************\n");
                var generator = new ProxyGenerator();
                var animal = generator.CreateInterfaceProxyWithoutTarget<IPlayable>(new AnimalInterceptor());
                animal.Play();

Console.WriteLine(animal.GetType());
                Console.WriteLine(animal.GetType().BaseType);

var compositeField = animal.GetType().GetField("__target");
                Console.WriteLine(compositeField);

foreach (var interfaceType in animal.GetType().GetInterfaces())
                {
                    Console.WriteLine(interfaceType);
                }
            }



动态代理的5模式使用示例和Mixin模式

第四种:InterfaceProxyWithTarget

复制代码 代码如下:


{
                Console.WriteLine("\n*************InterfaceProxyWithTarget*************\n");
                var generator = new ProxyGenerator();
                var animal = generator.CreateInterfaceProxyWithTarget<IPlayable>(new Dog(), new AnimalInterceptor());
                animal.Play();

Console.WriteLine(animal.GetType());
                Console.WriteLine(animal.GetType().BaseType);

var compositeField = animal.GetType().GetField("__target");
                Console.WriteLine(compositeField);

foreach (var interfaceType in animal.GetType().GetInterfaces())
                {
                    Console.WriteLine(interfaceType);
                }
            }



动态代理的5模式使用示例和Mixin模式

第五种:InterfaceProxyWithTargetInterface

复制代码 代码如下:


{
                Console.WriteLine("\n*************InterfaceProxyWithTargetInterface*************\n");
                var generator = new ProxyGenerator();
                var animal = generator.CreateInterfaceProxyWithTargetInterface<IPlayable>(new Dog(), new AnimalInterceptor());
                animal.Play();

Console.WriteLine(animal.GetType());
                Console.WriteLine(animal.GetType().BaseType);

var compositeField = animal.GetType().GetField("__target");
                Console.WriteLine(compositeField);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgydp.html