Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validating on Overridable method
Message
De
05/09/2011 13:06:48
 
 
À
05/09/2011 12:43:00
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01522449
Message ID:
01522746
Vues:
24
>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.
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform