ch-robinson / dotnet-avro

An Avro implementation for .NET
https://engineering.chrobinson.com/dotnet-avro/
MIT License
134 stars 49 forks source link

Support `[Range]` for inferring decimal precision and scale #216

Closed dstelljes closed 2 years ago

dstelljes commented 2 years ago

This change makes it possible to override the default precision and scale for generated decimal schemas by setting the [Range] attribute on a field or property.

We can’t infer anything from the int or double overloads, so the annotation has to be of the form [Range(typeof(decimal), "0.00", "1.00"]. It’s sort of ugly, especially since ConvertValueInInvariantCulture should be set as well (as shown in the new fixture class), but it’s a legitimate way to set the range and jibes with our preference for built-in annotations instead of our own. This post has a good, if dated, description of the footguns.

dstelljes commented 2 years ago

Good enough for me