-
Notifications
You must be signed in to change notification settings - Fork 8
Parameter resolving attributes
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.
- Getting started
- Basics (Http GET & Base Location)
- Basics pt. 2 (POST/PUT/DELETE, HttpResponseMessage, Exceptions, HttpClient, IDisposable)
- Building an HttpRequestMessage
- Parameter attributes
- Handling responses
- ApiSettings
- Typical setup (Develop/Test/Production & Mocking)
- Logging
- Testing
- Generic Api
- Multipart