VB.NETで実行中のクラス名とメソッド名を取得する
# 5年ぶりにMS系のプロジェクト参画中...
実行中のメソッドを取得する方法をmemoる
- FQCNは
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName
- メソッドシグネチャは
System.Reflection.MethodBase.GetCurrentMethod().ToString
サンプルと結果
Namespace org.hoge Public Class Test1 Public Shared Sub Main() Debug.Print(f1("クラス名とメソッドは")) End Sub Private Shared Function f1(prifix As String) As String Dim method As System.Reflection.MethodBase = System.Reflection.MethodBase.GetCurrentMethod() Dim fqcnAndMethodSignature As String = method.DeclaringType.FullName & "#" & method.ToString Return prifix & fqcnAndMethodSignature End Function End Class End Namespace
結果
クラス名とメソッドはConsoleApplication1.org.hoge.Test1#System.String f1(System.String)
Work! Enjoy it!