Forgive me if this is documented somewhere, but is there any nice way to create a MethodInvoker which will perform a specified function with specified arguments (capturing the argument values when the MethodInvoker is created)? I've sometimes done things by using a wrapper class, but wonder if that's the best approach. Should I be doing something like:
Class Invoker(Of T) ReadOnly Param1 As T ReadOnly Act As Action(Of T) ReadOnly execDelegate As New MethodInvoker(AddressOf execProc) Private Sub New(ByVal param1 As T, ByVal act As Action(Of T)) Me.Param1 = param1 Me.Act = act End Sub Private Sub execProc() Act(Param1) End Sub Shared Function Create(ByVal param1 As T, ByVal act As Action(Of T)) As MethodInvoker Dim newAction As New Invoker(Of T)(param1, act) Return newAction.execDelegate End Function End Class
and using e.g. "myMethodInvoker = Invoker(Of Integer).Create(6, AddressOf MyRoutine)" to create a delegate which will, when invoked, call MyRoutine(6)? Or is there some built-in support for doing that?