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

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



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

Mixin模式

复制代码 代码如下:


{
                Console.WriteLine("\n*************Mixin*************\n");
                var generator = new ProxyGenerator();
                var options = new ProxyGenerationOptions();
                options.AddMixinInstance(new RunAbility());
                var animal = generator.CreateClassProxy<Animal>(options, new AnimalInterceptor());
                animal.Play();
                (animal as IRunable).Run();

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

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

foreach (var field in animal.GetType().GetFields())
                {
                    if (field.Name.StartsWith("__mixin"))
                    {
                        Console.WriteLine(field);
                    }
                }

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



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

 
   

 

您可能感兴趣的文章:

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

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