Give a function with any number of arguments as parameter to another function.
i know how to pass a function with 0 to 16 arguments as parameter, however having this constraint by the Action or Func types, as far as i know, does not allow me to pass in a function with no arguments and later one with 2 arguments. is there perhaps any way that i could do this?
6 Replies
Well, that would be kind of hard to reason about
If a function you pass can have zero or two parameters, how do you call it?
func()
won't work if there are two params
func(1, 2)
won't work if there are no paramsim gonna use reflections to call the method itself, however i want to spare myself the typework to constantly have to type
GetType().GetMethod("methodName", bindingflags, argumentTypes)
if at all possible
i have an array of objects to use as the actual parameters for the method, so that wont be the issue eitherwait what
i have a button that i want to be able to give essentially any method that returns void, whether it takes 0 or however many arguments. when invoked it will use the associated array of objects as its arguments
though i do not know how i would go about doing this
or if its even possible >.<
You could maybe create a delegate like
delegate void Foo(params object[] stuff)
And use that Foo
instead of your Func
or Action
That's a big maybe thoughhmm
that wouldnt do what i want it to
as it would pass in one argument with that array, and not accept a method that would look like
void Foo(string bar)