Creating delegate to pass function with parameters (.net 2.0)

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 eg "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?

链接地址: http://www.djcxy.com/p/52788.html

上一篇: Vb.Net中的进度条和XML

下一篇: 创建委托以使用参数传递函数(.net 2.0)