可能重复:
如何找到调用当前方法的方法?
嗨,我怎样才能从方法中确定方法的调用者?例如:
SomeNamespace.SomeClass.SomeMethod() {
OtherClass();
}
OtherClass() {
// Here I would like to able to know that the caller is SomeNamespace.SomeClass.SomeMethod
}
Run Code Online (Sandbox Code Playgroud)
谢谢
这些文章应该有所帮助:
基本上代码看起来像这样:
StackFrame frame = new StackFrame(1);
MethodBase method = frame.GetMethod();
message = String.Format("{0}.{1} : {2}",
method.DeclaringType.FullName, method.Name, message);
Console.WriteLine(message);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10633 次 |
| 最近记录: |