2016-04-19 5 views
0

にキャストする方法引数を含むActionクラスとしてメソッド呼び出しをキャストする方法はありますか?それも可能ですか?城ウィンザー - メソッドを傍受し、それをアクションクラス

Queue<Action> queue = new Queue<Action>(); 

傍受されるためのサンプル方法:

public string DoSomeStuff(string[] arr) 
{ 
    //some logic here 
} 

インターセプター(城ウィンザー):

public class MyInterceptor : IInterceptor 
{ 
    public void Intercept(IInvocation invocation) 
    { 
     if (queue.Count > 0) 
     { 
      queue.Enqueue(() => { 
       //here, add intercepted method (DoSomeStuff) and its parameters 
      }); 
     }     
    } 
} 

答えて

1

エンキューは単純です:

public void Intercept(IInvocation invocation) 
{ 
    queue.Enqueue(invocation.Proceed); 
    ... 
} 

しかし、これはかなり無意味ですあなたはデリゲートがデキューされてからIntercept()メソッドから戻る前に呼び出されるまで待機します。

関連する問題