Asp.net .Net(C#)現在のネーミングスペース、クラス名、メソッド名を取得する方法
1026 ワード
以下の方法はインスタントウィンドウでは使用できませんので、皆さんがデバッグするときに注意してください.
メソッドに直接書いて出力してみてもいいですよ!
メソッドに直接書いて出力してみてもいいですよ!
public static string GetMethodInfo()
{
string str = "";
//
str += " :"+System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "
";
//
str += " :"+System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "
";
//
str += " :"+System.Reflection.MethodBase.GetCurrentMethod().Name + "
";
str += "
";
StackTrace ss = new StackTrace(true);
MethodBase mb = ss.GetFrame(1).GetMethod();
//
str += mb.DeclaringType.Namespace + "
";
//
str += mb.DeclaringType.Name + "
";
//
str += mb.DeclaringType.FullName + "
";
//
str += mb.Name + "
";
return str;
}
public static void Main()
{
Console.WriteLine(GetMethodInfo());
Console.ReadKey();
}