Skip to content

AddParameters() with dictionary throws 'Parameter count mismatch' on Resolve() #47

@BryanWilhite

Description

@BryanWilhite

Running in LinqPad:

void Main()
{
    var apiPath = "api/v2/{BrokerDealerId}/{PartyId}/Household/{HouseholdId}/Accounts";
    var template = new UriTemplate(apiPath);
    template.BindByPosition("BID1124", "PID6677", "HH3456").Dump();
}

static class UriTemplateExtensions
{
    public static string BindByPosition(this UriTemplate template, params string[] values)
    {
        if (template == null) throw new ArgumentNullException("template", "The expected URI template is not here.");

        var keys = template.GetParameterNames();

        var set = keys
            .Zip(values, (i, j) => new KeyValuePair<string, string>(i, j))
            .ToDictionary(i => i.Key, j => j.Value);

        return template.AddParameters(set).Resolve(); 
    }
}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wantedThis issue is available to submit a pull request for

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions