So currently you have to define every property to be added to a query. Perhaps we can refactor to be more generic. This was my solution but perhaps we can find a way that does not use Reflection:
private string ToCamelCaseString(string value)
{
return Char.ToLowerInvariant(value[0]) + value.Substring(1);
}
protected string ToQueryString<T>(T parameters)
{
List<string> query = new List<string>();
foreach (var property in parameters.GetType().GetProperties())
{
var value = GetPropertyValue(parameters, property.Name);
if (GetPropertyValue(parameters, property.Name) != null)
{
var queryItem = ToCamelCaseString(property.Name) + "=";
if (value.GetType().Name == "Boolean")
{
query.Add(queryItem + value.ToString().ToLower());
}
else
{
query.Add(queryItem + value.ToString());
}
}
}
return string.Join("&", query);
}`