【笔记】C#相关
最后一次更新时间:Saturday, May 22nd 2021, PM
获取当前方法信息(反射 Invoke)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public static string GetMethodInfo() { string str = ""; str += "命名空间名:" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "\n"; str += "类名:" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "\n"; str += "方法名:" + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n"; str += "\n";
StackTrace ss = new StackTrace(true); MethodBase mb = ss.GetFrame(1).GetMethod(); str += mb.DeclaringType.Namespace + "\n"; str += mb.DeclaringType.Name + "\n"; str += mb.DeclaringType.FullName + "\n"; str += mb.Name + "\n"; return str; }
|