2013-01-24 103 views
2

我有以下幾點。如何查詢類myExample並返回該類的方法名稱的數組?返回一個類方法名稱的數組

Sub Main() 
    Dim x As New myExample 

    '<<would like to return an array of x's method names i.e. {"hello","world","foo","bar"} 

    Console.WriteLine("press [enter] to exit") 
    Console.Read() 
End Sub 

Class myExample 

    Public Shared y As Integer 

    Public Sub hello() 
     y = 1 
    End Sub 
    Public Sub world() 
     y = 2 
    End Sub 
    Public Sub foo() 
     y = 3 
    End Sub 
    Public Sub bar() 
     y = 4 
    End Sub 
End Class 

回答

2

的所有方法(包括繼承的。):

Dim example As New myExample() 
Dim t As Type = example.GetType() 
Dim methods = t.GetMethods() 
Dim allMethodNames() As String = methods.Select(Function(m) m.Name).ToArray() 

Type.GetMethods

+0

1由於添 - 當場就照常 – whytheq

相關問題