-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type safety and improve type inference (#1374)
Some of the extension methods in `UnitMath.cs` (e.g. Average) take an `Enum unitType` argument. The compiler should be able to detect when the units type doesn't match the quantity type. * This will break backwards compatibility, but only for: * People doing really weird things. * People using the explicit generic type instead of inference (e.g. `Average<Length>(LengthUnit.Inch)`), in which case they can fix the code by changing it to e.g. `Average<Length, LengthUnit>(LengthUnit.Inch)` * This change might be warranted in `UnitConverter.cs` as well, but can't be implemented as a straight-forward refactor since it breaks compatibility in generated code (e.g. `unitConverter.SetConversionFunction<ElectricPotential>` in `ElectricPotential` should be `SetConversionFunction<ElectricPotential, ElectricPotentialUnit>` In addition, had to remove a few unit tests that were asserting type safety. All tests that were removed: * Were only testing that an incorrect behavior throws an exception (`Assert.Throws`) * Don't compile after the changes in `UnitMath.cs`
- Loading branch information
Showing
2 changed files
with
32 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters