Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Detecting method in sub class
Message
De
31/03/2015 09:26:01
 
 
À
31/03/2015 09:13:22
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01617154
Message ID:
01617488
Vues:
23
>>Doesn't work that way in C#. Be very surprised if that was the case in VB.NET - the type of 'Me' will be the type of the instance.
>
>If I would like to have it like this, how would I pass the 3rd parameter:
>
>
>    ' 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 toClass As Object, ByVal tcMethod As String, _
>     ByVal toBaseClass As Object) 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 = 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
>
>        ' If the method exists in the sub class
>        If loMethodInfo.DeclaringType <> toBaseClass.GetType() Then
>            llExist = True
>        End If
>
>        Return llExist
>    End Function
>
You couldn't (without walking the hierarchy). But since the IsMethodExistInSubClass() method is in the base class (so, by definition, you know the base class) I don't see why you need to pass it (or Me) at all. AFAICS your base class just needs to be something like this (check for non-existent method omitted):
Public Class FrameworkBaseClass

	Public Sub New()
		Dim check = IsMethodExistInSubClass("IniializeWithRow")
	End Sub

	Public Function IsMethodExistInSubClass(tcMethod As String) As Boolean
		Dim loType = Me.[GetType]()
		Dim loMethodInfo = loType.GetMethod(tcMethod, System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.[Public])
		Return  (loMethodInfo.DeclaringType <> GetType(FrameworkBaseClass))
	End Function

	Public Overridable Sub IniializeWithRow()
	End Sub
End Class
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform