Afk.Measure 2.3.0

dotnet add package Afk.Measure --version 2.3.0                
NuGet\Install-Package Afk.Measure -Version 2.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Afk.Measure" Version="2.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Afk.Measure --version 2.3.0                
#r "nuget: Afk.Measure, 2.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Afk.Measure as a Cake Addin
#addin nuget:?package=Afk.Measure&version=2.3.0

// Install Afk.Measure as a Cake Tool
#tool nuget:?package=Afk.Measure&version=2.3.0                

Measure

This library provides units management in different measure system (International System, CGS, Imperial system and US). The guidelines of SI can be found here

NUGET

The easiest way to install is by using NuGet.

Concept

The library expose Unit and Quantity<T>. Units belongs to a dimension (7 physical and 1 currency dimension), the quantity represents one value with associated unit. Operations like addition, substraction, comparaison are allowed only if unit of quantity belongs the same dimension. Conversion between quantities are done using the unit base converter. Each unit have a converter to go the unit base (SI unit), conversion from unit to another is built on merge of each unit converter.

Syntax

Units

The space character is not allowed as unit separator because it can be part of existing unit like fluid ounce "fl oz". The . or (char)183 are the unit multiplicator separator and the / is the unit divisor multiplicator. To obtain an unit you can use predefined units or try to parse a string :

        Unit unit = Unit.Parse("ms"); // Represents the milliseconds
        bool boolean = Unit.TryParse("skg", out unit); // Returns false
        boolean = Unit.TryParse("s.kg", out unit); // Returns true, seconds * gram
        unit = (Unit)"Wh"; // Represents the WattHour
        unit = SIPrefixe.Kilo * SI.METER; // Represents the km
        unit = (Unit)"m-2.kg/s"; // Represents m-2.kg.s-1
Quantity

Quantity is a generic class, the type can be anything until you need mathematical operations. Instanciations are done using constructor/static methods or by implicit conversion.

                Quantity<double> dd = 20; // Quantity unitless
                Acceleration<double> acc = 15; // Acceleration m.s-2
                Quantity<double> kg = 10 * SI.GRAM; // Gram 10kg
                Length<int> meter = 2; // Length 2m
                Quantity<double> meterAcc = acc * meter; // Quantity multiplication
                var tempK = Quantity.From<double>(SI.KELVIN, 293.15); // Quantity From
                var tempC = new Quantity<double>(20, "°C"); // Quantity constructor
                bool compare = tempK == tempC; // True

Prefix

Prefix are only authorize on SI unit. To avoid any confusion usage of multiple prefix is not allowed, for sample 10 MV.ms is not allowed, 10 kV is preferable. The prefix is put on numerator. This consideration do not apply on the kilogram which is the base unit from Gram, for sample 1 mol/kg will be preferable to 1 mmol/g. The Quantity class manage product of unit with prefix and will choose the best prefix to use.

Currency

The library manage physical units and currency unit. The base currency of the library is the euro. The currency unit convertion depends on exchange rate and can not be set at compile time. To manage the exchange rate you need to instanciate a CurrencyContext and specify the exchange rate between your currency and the euro. The CurrencyContext use TLS approach (ThreadLocalStorage) so is different for each threads.

                using (var context = new CurrencyContext())
                {
                    context.AddOrReplaceConverter("$", 0.87745);
                    context.AddOrReplaceConverter("¥", 0.00785);

                    var dollar = 1 * Unit.Parse("$");
                    Console.WriteLine("{0} Dollar to Yen : {1}", dollar.Value, dollar.ConvertTo("¥").Value);
                }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.0 257 12/26/2023
2.2.1 7,120 6/21/2019
2.2.0 2,553 1/16/2019
2.1.0 804 11/27/2018
2.0.2 1,056 6/4/2018
2.0.1 1,013 8/16/2017
2.0.0 1,118 8/15/2017
1.0.4 996 4/21/2017
1.0.3 1,475 7/13/2016
1.0.2 1,400 7/13/2016
1.0.1 1,518 4/6/2016