foreach (var interfaceType in animal.GetType().GetInterfaces())
{
Console.WriteLine(interfaceType);
}
}
第三种: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);
}
}
第四种: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);
}
}
第五种: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);