lundi 15 avril 2019

Can't get a list of declared methods in a .net class

Having read a great many posts on using reflection to get a list of methods in a given class, I am still having trouble getting that list and need to ask for help. This is my current code:

Function GetClassMethods(ByVal theType As Type) As List(Of String)
    Dim methodNames As New List(Of String)
    For Each method In theType.GetMethods()
        methodNames.Add(method.Name)
    Next
    Return methodNames
End Function

I call this method like this:

GetClassMethods(GetType(HomeController))

The return has 43 methods, but I only want the methods I wrote in the class. The image below shows the beginning of what was returned. My declared methods are in this list, but down at location 31-37. There are actually 9 declared methods, but this list doesn’t show the Private methods.

enter image description here

When I look at theType, I see the property I want. It is DeclaredMethods which shows every declared method, public and private.

enter image description here

However, I’m not able to access this property with a statement such as this.

Dim methodList = theType.DeclaredMethods()

The returned error is that DelaredMethods is not a member of Type. So, my questions are multiple:

1) Most important, what code do I need to retrieve every declared method in the class, and only the methods I declared?

2) Why am I not able to access the property that gives the list of DeclaredMethods()?





Aucun commentaire:

Enregistrer un commentaire