2012-01-04 103 views
0

我想獲取方法名稱並將其添加到列表中。我看了一下,發現了一些行爲。到目前爲止,我有以下幾點:強類型方法名稱

Protected Function MethodToString(method As Action) As String 

     Return method.Method.Name 

    End Function 

... 

    Me.Stages.Add(MethodToString(GetWeightFromSID())) 

,但因爲它說的表達不產生價值調用時它不工作。我幾乎只是在尋找方法的名稱。任何意見非常感謝。

回答

3

行動是一個委託,所以你需要通過address of the method,不調用方法:

Me.Stages.Add(MethodToString(AddressOf GetWeightFromSID)) 
+0

poifect :)謝謝! – deanvmc 2012-01-04 13:30:29

1

另一種方法是使用Reflection,例如獲取當前類的所有方法,名稱爲List(of String)

' get names of all properties and methods in the current class ' 
Dim methodNames = (From info In Me.GetType.GetMethods Select info.Name).ToList 
相關問題