Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validating on Overridable method
Message
From
05/09/2011 16:30:29
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01522449
Message ID:
01522759
Views:
25
Ok, I got this one working:
        ' 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 Originator
        ' expC1 Name of the method
        Public Function IsMethodExistInSubClass(ByVal toOriginator As Object, ByVal tcMethod As String) As Boolean
            Dim lcBaseClass As String = ""
            Dim lcClass As String = ""
            Dim llExist As Boolean = False
            Dim loType As Type = Nothing
            Dim loTypeParent As Type = Nothing
            Dim loMethodInfo As System.Reflection.MethodInfo = Nothing

            ' Get a reference to the originator type
            loType = toOriginator.GetType()

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

            ' Get a reference to the same object as well so we can climb up the chain for comparism
            loTypeParent = loType

            ' Loop until we have reached the base class
            While True

                ' If we have reached the object class
                If loTypeParent.Name = "Object" Then
                    Exit While
                Else

                    ' Get the class name
                    lcClass = loTypeParent.Name

                    loTypeParent = loTypeParent.BaseType
                End If

            End While

            ' Get the base class name
            lcBaseClass = lcClass

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

            Return llExist
        End Function
Not sure however if there is a way to simplify that.
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform