I would like to Invoke this method:
public IEnumerable<TEntity> SelectAll(params string[] entitiesToLoad)
But at the most of times I will not load relational entities, so I'd like to invoke it without send entitiesToLoad values, like this:
var dbResult = methodInfo.Invoke(repository, null);
But it throws an exception, because the number of parameter is not equivalent.
Is there a way to perform this without change the params string[] to another type of parameter?
I tried string entitiesToLoad = null as parameter
, I got the same error.
Pass an empty array, because that is what the C# compiler will pass when indicating no arguments for a variadic method:
var dbResult = methodInfo.Invoke(repository, new object[] { new string[0] });
Note that you will have to wrap the string array into an object array, because that object array represents the list of arguments. The first passed argument is then the empty string array.