paulcbetts/refit — pull request #55 by bennor (2014-10-10 23:24:05+00:00)
Title: Form property aliasing :bowtie:

Since there are dumb APIs out there with cryptic parameter names (looking at you [Google Measurement Protocol][1]), I've added support for the `[AliasAs("xyz")]` attribute to the serialization of object properties for use in form posts.

So now instead of:
```csharp
public interface IMeasurementProtocolApi
{
[Post("/collect")]
Task Collect([Body(BodySerializationMethod.UrlEncoded)] Measurement request);
}

public Measurement
{
public string t { get; set; } // This isn't even the worst of them
}

await api.Collect(new Measurement { t = "what even is t?" });

```
you can do this:
```csharp
// This part doesn't change
public interface IMeasurementProtocolApi
{
[Post("/collect")]
Task Collect([Body(BodySerializationMethod.UrlEncoded)] Measurement request);
}

// This stuff does
public Measurement
{
[AliasAs("t")]
public string Type { get; set; }
}

await api.Collect(new Measurement { Type = "event" });
```

A few things to note:

* I reused `AliasAsAttribute` instead of creating a new attribute (e.g. `FormAliasAttribute`, `FormFieldAttribute`, etc). This could maybe get a little confusing for consumers since it won't actually do anything if it's used with JSON serialization. Json.NET already has `JsonPropertyAttribute` for that though. If you'd prefer I create a new attribute to avoid any confusion, I'm happy to.
* The .NET 4.5 test project was busted, so I had to fix that. I'm not sure if it's what you intended - I just did what I needed to to get the test project running. I haven't fixed any of the other test projects.
* I don't have a Xamarin license, so I haven't been able to check the Xamarin solution. :imp:

[1]: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters