Seb*_*n K 3 .net c# castle-dynamicproxy
我可能遗漏了一些非常简单的东西.
我只是想写一个非常简约的DynamicProxy使用示例 - 我基本上想拦截调用并显示方法名称和参数值.我的代码如下:
public class FirstKindInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
Console.WriteLine("First kind interceptor before {0} call with parameter {1} ", invocation.Method.Name, invocation.Arguments[0]);
invocation.Proceed();
Console.WriteLine("First kind interceptor after the call");
}
}
public interface IFancyService
{
string GetResponse(string request);
}
public class FancyService : IFancyService
{
public string GetResponse(string request)
{
return "Did you just say '" + request + "'?";
}
}
class Program
{
static void Main(string[] args)
{
var service = new FancyService();
var interceptor = new FirstKindInterceptor();
var generator = new ProxyGenerator();
var proxy = generator.CreateClassProxyWithTarget<IFancyService>(service, new IInterceptor[] { interceptor } );
Console.WriteLine(proxy.GetResponse("what?"));
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,我得到以下异常:
未处理的异常:System.ArgumentException:'classToProxy'必须是类参数名:classToProxy
我错过了什么?
| 归档时间: |
|
| 查看次数: |
486 次 |
| 最近记录: |