It's crazy simple to get started, take the following code for example:
var builder = new Builder();
var obj = new MixedObject
{
ItemNames = new[] { "one", "two" },
TextMessage = "programming is fun"
};
var result = builder.ToQueryString(obj);
result.ShouldBe("?ItemNames=one&ItemNames=two&TextMessage=programming+is+fun");
Not a fan of Pascal Casing? You can use Camel Case as well.
var settings = new BuilderSettings { FieldCasing = FieldCasing.CamelCase };
var builder = new Builder(settings);
var result = builder.ToQueryString(new MixedObject { ItemNames = new[] { "one", "two" }, TextMessage = "programming is fun" });
result.ShouldBe("?itemNames=one&itemNames=two&textMessage=programming+is+fun");
You can override the default formatting of Arrays if you need.
var builder = new Builder(x =>
{
x.FieldArray = FieldArray.UseArraySyntax;
});
var result = builder.ToQueryString(new { cars = new[] { "Saab", "Audi", "Nissan", "Ford" } });
result.ShouldBe("?cars[]=Saab&cars[]=Audi&cars[]=Nissan&cars[]=Ford");
var builder = new Builder(x =>
{
x.FieldArray = FieldArray.UseCommas;
});
var result = builder.ToQueryString(new { cars = new[] { "Saab", "Audi", "Nissan", "Ford" } });
result.ShouldBe("?cars=Saab%2cAudi%2cNissan%2cFord");
Maybe Pascal or Camel casing isn't enough for you. You can transform your fields using a custom function like so:
var builder = new Builder(x =>
{
x.CustomFieldConverter = s => s.ToUpper();
});
var result = builder.ToQueryString(new { Test = "blah" });
result.ShouldBe("?TEST=blah");
- @ChrisMissal - code
- @timgthomas - logo
The MIT License Copyright (c) 2014 Chris Missal