I think that what you are looking for does not exist. The closest you have are the options:
MyMethod(params object[] args) { // if you have to do this, it quite bad: int intArg = (int)args[0]; string stringArg = (string)arg[1]: } // call with any number (and type) of argument MyMethod(7, "tr");
There is no compilation time type check, and therefore this is not a universal way of handling arguments. But if your arguments are dynamic, this is probably the solution.
Edit: there was another idea:
You need to put all arguments manually in a list / dictionary. You can write a helper class to allow the following:
MyMethod(int arg1, string arg2) { Arguments.Add(() => arg1); Arguments.Add(() => arg2); // }
The helper looks like this:
public static void Add<T>(Expression<Func<T>> expr) {
Stefan steinegger
source share