Using generics in dotnet for functions with any number of arguments?
- by Zarigani
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?