Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detecting method exists in class with reflection
Message
From
18/04/2016 11:39:44
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Detecting method exists in class with reflection
Environment versions
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01634928
Message ID:
01634928
Views:
60
I have this method to verify if a method exists in a class with reflection, but when this is an overrides:
    ' If a method exists in a sub class. This is used when we negotiate with the Overrides method. Thus, the framework
    ' may know if the Overrides method exists in the sub class. This is used in the DataEntry class. So, if the method
    ' does not exist, we do not call it. And, if it exists, it allows us to validate, if necessary, before proceeding.
    ' expO1 Class
    ' expC1 Name of the method
    Public Function IsMethodExistInSubClass(ByVal toClass As Object, ByVal tcMethod As String) As Boolean
        Dim llExist As Boolean = False
        Dim loType As Type = Nothing
        Dim loMethodInfo As System.Reflection.MethodInfo = Nothing

        ' Get a reference to the class type
        loType = toClass.GetType()

        ' Get a reference to the method
        loMethodInfo = loType.GetMethod(tcMethod, System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.Public)

        ' If the method does not exist
        If loMethodInfo Is Nothing Then
            Return False
        End If

        ' Loop until we have reached the base class
        While loType.BaseType <> GetType(Object)
            loType = loType.BaseType
        End While

        ' If the method exists in the sub class
        If loMethodInfo.DeclaringType <> loType Then
            llExist = True
        End If

        Return llExist
    End Function
Now, I need the same but to simply detect the presence of a method which is not an override.

Anyone would know what adjustment would be necessary?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform