I am trying to call Invokeon Dispatcherusing the following overload:
public object Invoke(Delegate method, params object[] args);
I want to use named arguments, but I cannot find the argument syntax with the params modifier. All of the following will not compile:
dispatcher.Invoke(method: () => { }, args: {});
dispatcher.Invoke(method: () => { }, args: new object[0]);
dispatcher.Invoke(method: () => { }, args: null);
dispatcher.Invoke(method: () => { }, args: new object[] {});
object[] foo = {};
dispatcher.Invoke(method: () => { }, args: foo);
dispatcher.Invoke(method: () => { }, args: new[] {"Hello", "World!"});
I found these two questions, which seem to have no definite answers:
Named parameters with parameters
How to set a named argument to string.Format?
So my question is: can this be done or not? If so, how?
UDPATE
Daniel Hilgart shows that yes paramscan be used with named parameters. I included his answer using this template:
Action method = () => { };
if (_dispatcher != null)
_dispatcher.Invoke(method: method, args: null);
else
method();
user610650
source
share