Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validating on Overridable method
Message
From
05/09/2011 13:23:28
 
 
To
05/09/2011 13:06:48
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:
01522748
Views:
17
>>Phew! I was just beginning to doubt myself and create my own test :-}
>
>In my Reflection class, I moved that code into it such as:
>
>
>        ' If a method exists in a sub class
>        ' expO1 Originator
>        ' expC1 Name of the method
>        ' expC2 Name of the base class
>        Public Function IsMethodExistInSubClass(ByVal toOriginator As Object, ByVal tcMethod As String, _
>         ByVal tcBaseClass 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 originator type
>            loType = toOriginator.GetType()
>
>            ' Get a reference to the method
>            loMethodInfo = loType.GetMethod(tcMethod, System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.Public)
>
>            ' If the method exists in the client class
>            If loMethodInfo.DeclaringType.Name <> tcBaseClass Then
>                llExist = True
>            End If
>
>            Return llExist
>        End Function
>
>
>In my DataEntry class, I added this:
>
>
>            Dim loReflection As Framework.Reflection = New Framework.Reflection(oProcess)
>
>            ' If the method exists in the client class
>            If loReflection.IsMethodExistInSubClass(Me, "InitializeWithRow", "DataEntry") Then
>
>                ' Just in case the user manipulated the URL
>                If nPrimaryKey = 0 Then
>                    oProcess.oResponse.Redirect("Default.aspx")
>                End If
>
>            End If
>
>
>Now, in this design, I am passing a 3rd parameter which represents the name of the baseclass. I was wondering if from the Reflection class, I can detect that automatically, thus making it only to have to pass two parameters, the object itself of the class and the name of the overridable method I would like to check for.

Maybe
loType.BaseType.Name
Untested. And it only gives the immediate parent - if the actual class has a deeper hierarchy it won't work.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform