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

Form property aliasing #55

Merged
merged 2 commits into from
Oct 12, 2014
Merged

Form property aliasing #55

merged 2 commits into from
Oct 12, 2014

Conversation

bennor
Copy link
Contributor

@bennor bennor commented Oct 10, 2014

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

So now instead of:

public interface IMeasurementProtocolApi
{
    [Post("/collect")]
    Task Collect([Body(BodySerializationMethod.UrlEncoded)] Measurement measurement);
}

public class 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:

// This part doesn't change
public interface IMeasurementProtocolApi
{
    [Post("/collect")]
    Task Collect([Body(BodySerializationMethod.UrlEncoded)] Measurement measurement);
}

// 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 what I did is 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. 👿

@bennor bennor changed the title Form property aliasing :bowtie: Form property aliasing Oct 10, 2014
@anaisbetts
Copy link
Member

This looks great! Can you document this in the README too?

@bennor
Copy link
Contributor Author

bennor commented Oct 11, 2014

Yeah man. Was just waiting to make sure it was all good before I wrote any
docs. :) We didn't update them when I added form support. Oops.

Saw you used the form post stuff for the slack api in your evolve talk,
which made me 😸. It's very cool seeing the guy who wrote a
library using the little bit I wrote for it. How cool is open source!
On 11/10/2014 3:00 pm, "Paul Betts" notifications@github.com wrote:

This looks great! Can you document this in the README too?


Reply to this email directly or view it on GitHub
#55 (comment).

@anaisbetts
Copy link
Member

@bennor Totally! :) Once we get iOS 64-bit working, this library will really take off

@anaisbetts anaisbetts merged commit e53a099 into reactiveui:master Oct 12, 2014
anaisbetts added a commit that referenced this pull request Oct 12, 2014
Conflicts:
	Refit-Tests/packages.Refit-Tests-Net45.config
	packages/repositories.config
@anaisbetts
Copy link
Member

Merged! Thanks @bennor!

@bennor bennor deleted the form-property-aliasing branch October 12, 2014 20:38
@lock lock bot locked and limited conversation to collaborators Jun 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants