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();
}
/// 取得当前源码的哪一行
/// </summary>
/// <returns></returns>
public static int GetLineNum()
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1, true);
return st.GetFrame(0).GetFileLineNumber();
}
/// <summary>
/// 取当前源码的源文件名
/// </summary>
/// <returns></returns>
public static string GetCurSourceFileName()
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1, true);
return st.GetFrame(0).GetFileName();
}