Azure / Azure/azure-functions-host
TypeConverter support for model binding
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
#### What problem would the feature you're requesting solve? Please describe.
I'm creating Azure Functions that use HttpTriggers, and using custom types as parameters to my functions to leverage model binding.
This works well on the whole, but on one of my models I have a string property that should always be passed in using the format "hh:mm:ss:ff", so ideally I'd like to create a custom type for this property and use a TypeConverter to convert it from a string property to my custom type.
I believe this functionality exists in ASP.NET Core MVC, as explained [here](https://docs.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-model-binding?view=aspnetcore-3.1#model-binding-review), but does not appear to exist in Azure Functions.
#### Describe the solution you'd like
I'd like to declare a custom type annotated with a `[TypeConverter(typeof(...))]` attribute. The TypeConverter is then used to convert the property value from a string to the declared type when model binding is performed.
#### Describe alternatives you've considered
At the moment, I am declaring the type as a string and manually validating and converting the property value.
#### Additional context
I am using "GET" requests to my Azure Function, so the model binding described above is actually binding URL parameters to my model, and not JSON.
Contributor guide
Research direction
Start at the HttpTriggers model-binding entry point and trace how URL parameters are converted to custom model properties. Check whether the existing binding path has tests for custom types or conversion failures. Done means a [TypeConverter] attribute can convert URL-bound string properties while existing model binding continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100