実際、私が求めていることを理解しやすくするための質問はほとんどありません。最初にコードを表示する必要があります。
public static void Main(string[] args)
{
CustomClass customClass = new CustomClass();
customClass.SomeMethod("asdas", true, 30.5);
}
public class CustomClass
{
[MyAttribute]
public Boolean SomeMethod(String a, Boolean b, Double c)
{
return true;
}
}
public class MyAttribute : Attribute
{
public MyAttribute()
{
SomeIntercepter.InterceptEverything();
}
public void DoSomethingBeforeMethodexecutes()
{
....
}
public void DoSomethingAfterMethodExecutes()
{
....
}
}
public class SomeIntercepter
{
public static void InterceptEverything()
{
StackTrace stackTrace = new StackTrace();
var method = stackTrace.GetFrame(2).GetMethod();
var parameters = method.GetParameters();
if (parameters.Length > 3)
return;
String cacheKey = method.Name;
for (int i = 0; i < parameters.Length; i++)
{
//HOW TO GET THE PARAMETER DATA ASSIGNED
cacheKey += "_" + parameters[i];
}
}
}
だから私がやろうとしていること。呼び出されるたびにメソッドをインターセプトし、 でマークされたメソッドの受信データに基づいて何かをしようとし[MyAttribute]
ます。そのため、StackTrace を介してメソッドにアクセスし、GetParameters を使用してすべての着信データを取得しようとします。SomeMethod
そして、ここに私の質問があります: 1) InterceptEverything()のすべての受信データの object[] の方法 2)MyAttribute
マークされたメソッドの前にMyAttribute
実行するメソッドを実行する方法DoSomethingBeforeMethodexecutes()
3) MyAttribute
後に実行するメソッドに言う方法メソッドMyAttribute
を実行するためのマークされたメソッドDoSomethingAfterMethodexecutes()
アドバイスをありがとう。