Skip to content

Parameter resolving attributes

Mattias Nordqvist edited this page Apr 18, 2015 · 5 revisions

Parameter resolving as introduced in Parameter resolving is powerful but a bit blunt as they affect all parameters. Another way to use parameter resolvers is to implement them as parameters and decorate them on an API-level, method level or even at parameter level. Fact is that the Alias attribute is implemented in the same way as any other custom attribute would be.

public class AliasAttribute : ParameterResolverAttribute
{
    private readonly string _alias;

    public AliasAttribute(string alias)
    {
        _alias = alias;
    }

    public override void Resolve(Parameter parameter)
    {
        parameter.Name = _alias;
    }
}

The key is to extend the ParameterResolverAttribute and implement the Resolve method. The resolve method is then able to modify the parameter sent into it. There are two properties that you can modify to change how the url parameter is rendered. Name and Value. Name will translate to the part to the left of the equals-sign, while Value is the value to the right off the equals-sign. If the parameter is an url segment, then the Name property is not really of any interest.

Documentation (v6.1.0)

  1. Getting started
  2. Basics (Http GET & Base Location)
  3. Basics pt. 2 (POST/PUT/DELETE, HttpResponseMessage, Exceptions, HttpClient, IDisposable)
  4. Building an HttpRequestMessage
  5. Parameter attributes
  6. Handling responses
  7. ApiSettings
  8. Typical setup (Develop/Test/Production & Mocking)
  9. Logging
  10. Testing
  11. Generic Api
  12. Multipart
Clone this wiki locally