RedStar.Amounts
4.1.5
dotnet add package RedStar.Amounts --version 4.1.5
NuGet\Install-Package RedStar.Amounts -Version 4.1.5
<PackageReference Include="RedStar.Amounts" Version="4.1.5" />
paket add RedStar.Amounts --version 4.1.5
#r "nuget: RedStar.Amounts, 4.1.5"
// Install RedStar.Amounts as a Cake Addin
#addin nuget:?package=RedStar.Amounts&version=4.1.5
// Install RedStar.Amounts as a Cake Tool
#tool nuget:?package=RedStar.Amounts&version=4.1.5
RedStar.Amounts
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:
- 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.
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.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on RedStar.Amounts:
Package | Downloads |
---|---|
RedStar.Amounts.StandardUnits
Standard units to use with the RedStar.Amounts package. These contain units that are part of the International System of Units (or SI, from the French Système Internationale). |
|
RedStar.Amounts.JsonNet
Custom converters for serializing and deseriazling RedStar.Amounts types to JSON using NewtonSoft's JSON.NET library. |
GitHub repositories
This package is not used by any popular GitHub repositories.