Commit 372daea
authored
Standardize quantity formatting on .NET numeric formats (#1721)
## Motivation
UnitsNet v6 has already removed the proprietary `U`, `V`, and `Q`
quantity format strings. This completes that cleanup by removing the
remaining `A` and `S` formats, so quantity format parameters
consistently accept .NET numeric format strings and can be described
accurately with `StringSyntaxAttribute.NumericFormat`.
The historical rationale supports the cleanup:
- `A` only returns unit abbreviations, which are already available
explicitly through generated `GetAbbreviation()` APIs and the
configurable `UnitAbbreviationsCache`.
- #797 intended to remove `S`, and commit 721287d removed its
documentation and tests, but the formatter implementation remained in
v5. This PR completes that cleanup. The discussion in #1450 also noted
that `S` can hide precision and that callers should choose an explicit
numeric format.
## Changes
- Remove `A`/`An` and `S`/`Sn` formatting from `QuantityFormatter` and
`QuantityValue`.
- Throw focused `FormatException` messages for those formerly recognized
formats with migration guidance.
- Keep standard and custom .NET numeric formats, such as `G3`, `F2`,
`N2`, `E2`, and `0.##`.
- Annotate generated quantity formatting, `QuantityFormatter`,
`QuantityValue`, quantity extensions, and type-converter formatting with
`StringSyntaxAttribute.NumericFormat`.
- Add an internal `StringSyntaxAttribute` compatibility definition for
the `netstandard2.0` target.
- Regenerate quantities and tests, and update the string-formatting
guide and v6 upgrade guide.
## Migration
| Removed | Replacement |
|---|---|
| `A`, `A0`, `A1`, ... | `Length.GetAbbreviation(unit)` or
`UnitAbbreviationsCache.GetUnitAbbreviations(unit)` |
| `S`, `S2`, ... | An explicit standard/custom numeric format such as
`G3`, `F2`, `N2`, `E2`, or `0.##` |
| `U` | `quantity.Unit` |
| `V` | `quantity.Value` |
| `Q` | Static metadata such as `Length.Info.Name` |
Currency (`C`) and percent (`P`) formats remain intentionally
unsupported for physical quantities.
Refs #1200.
## Validation
- `generate-code.bat`
- `dotnet build UnitsNet/UnitsNet.csproj --no-restore`
(`netstandard2.0`, `net8.0`, `net9.0`, `net10.0`)
- `dotnet test UnitsNet.Tests --no-restore -f net10.0` (52,506 passed,
16 skipped)
- `dotnet test UnitsNet.Tests --no-restore -f net48` (45,321 passed, 16
skipped)1 parent 82994b0 commit 372daea
272 files changed
Lines changed: 615 additions & 3457 deletions
File tree
- CodeGen/Generators/UnitsNetGen
- Docs
- UnitsNet.Tests
- CustomCode/ValueTests
- GeneratedCode/TestsBase
- UnitsNet
- CustomCode
- Compatibility
- Value
- Extensions
- GeneratedCode/Quantities
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1032 | 1032 | | |
1033 | 1033 | | |
1034 | 1034 | | |
1035 | | - | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
1036 | 1038 | | |
1037 | 1039 | | |
1038 | 1040 | | |
| |||
Lines changed: 0 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1255 | 1255 | | |
1256 | 1256 | | |
1257 | 1257 | | |
1258 | | - | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
1268 | | - | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | 1258 | | |
1279 | 1259 | | |
1280 | 1260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | | - | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | | - | |
18 | | - | |
| 22 | + | |
19 | 23 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | | - | |
| 29 | + | |
27 | 30 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 31 | + | |
35 | 32 | | |
36 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | | - | |
| 42 | + | |
| 43 | + | |
39 | 44 | | |
40 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
41 | 48 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 49 | + | |
48 | 50 | | |
49 | | - | |
| 51 | + | |
50 | 52 | | |
51 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
65 | 74 | | |
66 | 75 | | |
67 | 76 | | |
| |||
0 commit comments