0

我不知道如何正确解释我想要的。这是一个例子^

public void foo()
{
  StackFrame trace = new StackFrame(1);
  MethodBase method = trace.GetMethod(); //so, here we'll get bar-method info
  MthodBody body = method.GetMethodBody(); //and here we'll get bar-method body
  /*now i need get access to the local vars in bar
    i know about MethodBody.LocalVariables
    but i don't have any idea how i can get values of variables i and hello,
    that defined in bar-method. I think it may be possible if i'll get
    pointers to the vars,
    and then copy it with Marshal.Copy*/
}

public void bar()
{
  int i = 42;
  string hello = "Hello!";
  foo();
}

PS我希望我的例子并不可怕,你明白我到底想要什么。 PPS对不起,我的英语很糟糕:)

4

1 回答 1

0

我想,您真正想做的是某种方法拦截(我认为您正在尝试记录参数值或类似的东西)。看看 PostSharp http://www.sharpcrafters.com/blog/post/Day-7-Interception-Aspects-e28093-Part-1.aspx或Castle Windsor 中的DynamicProxy

于 2012-04-12T20:00:26.783 回答