This project may seem dormant, but it is mainly due to having reach a stable point. It is still actively being maintained and is safe to use in production applications. If you encounter any issues or need extra features, don't hesitate to create an issue.
RedStar.Amounts contains classes to easily work with unit and amounts.
Too often, applications use integers, doubles, etc. to indicate distances, weights, and other measured values. This can cause problems because assumptions are made on the units, conversions have to be done, etc.
This can cause hard-to-trace bugs and leads to less readable code.
Say you have a public service (WCF, REST, ...) that takes in measurements from an external service. Which of the following do you prefer?
public class SomeService
{
public void ReportMeasurement(double length, double height)
{
// external system sends values in meters, but we work with cm
var lengthInCm = length * 100;
var heightInCm = height * 100;
var area = lengthInCm * heightInCm;
...
}
}
Or this:
public class SomeService
{
public void ReportMeasurement(Amount length, Amount height)
{
var area = length * height;
...
}
}
In the second example, the area
variable will automatically have a value and
a unit. The unit will be m².
This makes it easier and more fail-proof to do calculations later.
RedStar.Amounts consists of three Nuget packages:
- RedStar.Amounts: the core library
- RedStar.Amounts.StandardUnits: most likely what you need, will include standard units (length, weight, energy, etc)
- RedStar.Amounts.JsonNet: includes custom converters for JSON.NET
Packages are released according to semantic versioning and all latest versions should work together without any problems.
You can find the latest documentation here.
This library targets .NET Standard 2.0.
This code was taken and built upon from CodeProject. Credit is due to Rudi Breedenraedt. The code is licensed under the CPOL.