Using generics in dotnet for functions with any number of arguments?

Posted by Zarigani on Stack Overflow See other posts from Stack Overflow or by Zarigani
Published on 2010-04-21T21:42:31Z Indexed on 2010/04/21 21:43 UTC
Read the original article Hit count: 189

Filed under:
|

I would like to have a function that can "wrap" any other function call. In this particular case, it would allow me to write some more generic transaction handling around some specific operations.

I can write this for any particular number of arguments, e.g. for one argument:

Public Shared Sub WrapFunc(Of T)(ByVal f As Action(Of T), ByVal arg As T)
    ' Test some stuff, start transaction
    f(arg)
    ' Test some stuff, end transaction
End Sub

... but I was hoping to have this handle any number of arguments without having to have duplicate code for 0 args, 1 arg, 2 args, etc.

Is there a way of doing this?

© Stack Overflow or respective owner

Related posts about dotnet

Related posts about generics