Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BryanWilhite opened this issue Oct 24, 2017 · 1 comment
Labels
enhancement help wanted This issue is available to submit a pull request for

Comments

@BryanWilhite
Copy link

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

@BryanWilhite
Copy link
Author

BryanWilhite commented Oct 24, 2017

BTW this works fine:

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();
        for (int i = 0; i < keys.Count(); i++)
        {
            template.AddParameter(keys.ElementAt(i), values.ElementAtOrDefault(i));
        }

        return template.Resolve(); 
    }
}

@baywet baywet added the help wanted This issue is available to submit a pull request for label Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted This issue is available to submit a pull request for
Projects
None yet
Development

No branches or pull requests

3 participants