MethodInfo.Invoke parameter order
c#, reflection
Solution
Is there a way to specific which values goes on which parameter by name?
Well, you specify them in parameter order. So if you want to map specific values to specific names, you should fetch the parameter list with `method.GetParameters` and map them that way. For example, if you had a `Dictionary<string, object>` with the parameters:
var arguments = method.GetParameters()
.Select(p => dictionary[p.Name])
.ToArray();
method.Invoke(instance, arguments);
Problem
I'm trying to invoke a method using reflection. Something like this: ``` method.Invoke(instance, propValues.ToArray()) ``` The problem is that there isn't a way to ensure the array of parameters is in the right order. Is there a way to specific which values goes on which parameter by name? Or do I really have to make a custom binder? If so, can anyone guide me in the right direction?