I'm just testing reflection things for curiosity and I'm trying to invoke a private method but I can't find it because is Private
.
But what I really would like to know is if the visibility of the method could be automatically retrieved in the reflection search to don't worry about if the method to invoke is private, shared, friend, public etc... so there is a BindingFlags
flags combination to be able to invoke a method indifferently of which is the method visibility?, I mean without worrying about the method visibility.
Here is my code:
Public Class Form1
Private Shadows Sub Load() Handles MyBase.Load
Dim Method As System.Reflection.MethodInfo = Me.GetType().GetMethod("Test")
If Method IsNot Nothing Then
Method.Invoke(Me, BindingFlags.InvokeMethod Or BindingFlags.NonPublic, Nothing,
New Object() {"Hello World!", Type.Missing}, CultureInfo.InvariantCulture)
Else
MsgBox("Method not found or maybe is not public.")
End If
End Sub
Private Sub Test(ByVal Value As String, Optional ByVal Value2 As Integer = 1)
MsgBox(Value)
End Sub
End Class