Delegate doesn't seem to register 'params'

The params keyword of C# allows equivalence between Array and parameter-list, does it not?

Sadly, in my implementation, this isn't the case.

private Entities queryType(String entitiesType, params KeyValuePair<String, object>[] values)
{
    addStandardHeaders();
    String query = parsePredicate(values);
    Task<HttpResponseMessage> filterTask = client.GetAsync(client.BaseAddress + RESTapi.ALMentitiesQuery(domain, project, entitiesType, query));
    Task.WaitAny(filterTask);
    //Callback:
    HttpResponseMessage result = filterTask.Result;
    if (result.IsSuccessStatusCode)
    {
        updateCookies(client.BaseAddress+RESTapi.ALMentitiesQuery(domain, project, entitiesType, query));
        mainHeaders.Clear();
        Task<Stream> output = result.Content.ReadAsStreamAsync();
        Task.WaitAny(output);
        //Callback:
        return (Entities)fromJSON(output.Result, typeof(Entities)); 
    }
    else
    {
        util.Exception exception = getException(result);
        throw new HttpException(exception.Title);
    }
}

The delegate:

public delegate Entities SubTypeQuery(String subType, params KeyValuePair<String, object>[] values);

In application:

public List<Run> getRuns()
{
    List<Entity> selection = ((Entities)subTypeSelector.DynamicInvoke(
        ALMObject.Run.entitiesName(),
        (new KeyValuePair<String, object>("testcycle-id", id))
    )).entities.ToList<Entity>();

    List<Run> runSet = new List<Run>();
    foreach (Entity element in selection)
        runSet.Add(new Run(element, subTypeSelector));
    return runSet;
}

At run-time I get a Type-Exception: "Cannot convert KeyValuePair<String, object> to KeyValuePair<String, object>[]". This renders params completely useless. Suggestions?

Jon Skeet
people
quotationmark

The params keyword of C# allows equivalence between Array and parameter-list, does it not?

When the C# (or VB) compiler is involved, yes. Not when you're using reflection.

The problem is that you're invoking the delegate dynamically - with reflection, basically. Reflection code doesn't take any notice of params. You either need to invoke the delegate directly (without DynamicInvoke) or create the array explicitly.

people

See more on this question at Stackoverflow