Asp.net .net(C#) 获取当前命名空间,类名,方法名的方法
转载
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().DeclaringType.Name+
"\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;
}
public
static
void
Main()
{
Console.WriteLine(GetMethodInfo());
Console.ReadKey();
}
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。