Skip to content

Easy working with units and amounts; no more weird conversion or hard-to-trace bugs

License

Notifications You must be signed in to change notification settings

cidzoo/RedStar.Amounts

 
 

Repository files navigation

RedStar.Amounts

Build status

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.

Installation

RedStar.Amounts consists of three Nuget packages:

Packages are released according to semantic versioning and all latest versions should work together without any problems.

Documentation

You can find the latest documentation here.

.NET versions

This library targets .NET Standard 2.0.

Source, license

This code was taken and built upon from CodeProject. Credit is due to Rudi Breedenraedt. The code is licensed under the CPOL.

About

Easy working with units and amounts; no more weird conversion or hard-to-trace bugs

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 80.4%
  • C# 19.6%