Hi
I want to store methods in a List/Arraylist Class with different parameters.
Until now I declared a delegate which has the same parameters as the method to store,
then within a method I declared another variable as the delegate,
then I assigned the address of the method.
Simply put I did this:
But now I want to pass methods whose parameters I don't know beforehand and
therefore can't declare a delegate for it.
What I want to be able to do:
Any idea how to pull this off?
I want to store methods in a List/Arraylist Class with different parameters.
Until now I declared a delegate which has the same parameters as the method to store,
then within a method I declared another variable as the delegate,
then I assigned the address of the method.
Simply put I did this:
Visual Basic:
Class Main
Delegate Sub Exec(ByVal Code As String)
Private Sub Test(ByVal Code As String)
Dim TestSub As New Exec(AddressOf Test)
TestSub(Code) 'I know it loops, it is just to demonstrate :)
End Sub
End Class
But now I want to pass methods whose parameters I don't know beforehand and
therefore can't declare a delegate for it.
What I want to be able to do:
Visual Basic:
Class Main 'Would be great if it worked he he
Dim Methods As List(Of [Delegate])
Private Sub ProgramStartsHere()
Methods.Add(AddressOf DoSomething1)
Methods.Add(AddressOf DoSomething2)
Methods.Add(AddressOf DoSomething3)
Methods(0)("bla")
Methods(1)(5)
Methods(2)("bla", 5)
End Sub
'Random Subs with unkown params
Private Sub DoSomething1(ByVal Bla As String)
End Sub
Private Sub DoSomething2(ByVal bla As Integer)
End Sub
Private Sub DoSomething3(ByVal bla As String, ByVal bla2 As Integer)
End Sub
End Class
Any idea how to pull this off?