[英]Castle Windsor - intercept method and cast it to Action class
how to cast the method invocation as an Action
class including its arguments ? 如何将方法调用转换为包含其参数的Action
类? Is it even possible ? 可能吗?
Queue<Action> queue = new Queue<Action>();
sample method to be intercepted: 要拦截的样本方法:
public string DoSomeStuff(string[] arr)
{
//some logic here
}
interceptor (Castle Windsor): 拦截器(城堡温莎堡):
public class MyInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
if (queue.Count > 0)
{
queue.Enqueue(() => {
//here, add intercepted method (DoSomeStuff) and its parameters
});
}
}
}
Enqueuing is straight forward: 入队很简单:
public void Intercept(IInvocation invocation)
{
queue.Enqueue(invocation.Proceed);
...
}
But this is pretty pointless since you will have to wait until the delegate is dequeued and invoked before returning from your Intercept() method. 但这是毫无意义的,因为在从Intercept()方法返回之前,您将不得不等待委托出队并被调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.