Search code examples
.net-corerestsharp

AddQueryParameter using AddObject with null values


In section about parameters, there's a paragraph that allows to use AddObject instead of several AddParameters:

var params = new {
    status = 1,
    priority = "high",
    ids = new [] { "123", "456" }
};
request.AddObject(params);

There are two questions:

  1. Is it possible to use for query parameters?
  2. What will be if there is null value? Exception? Just not added query parameter?

Solution

  • Answering on my questions:

    1. If the developer makes GET request, it will treat it as query parameters by default. If the developer makes POST request, it will work as AddParameter, hence developer should use AddQueryParameter.
    2. If in an anonymous object you have null value, it will be ignored and not added to parameter.