DoenaSoft.UnitsOfMeasurement
1.0.4
See the version list below for details.
dotnet add package DoenaSoft.UnitsOfMeasurement --version 1.0.4
NuGet\Install-Package DoenaSoft.UnitsOfMeasurement -Version 1.0.4
<PackageReference Include="DoenaSoft.UnitsOfMeasurement" Version="1.0.4" />
paket add DoenaSoft.UnitsOfMeasurement --version 1.0.4
#r "nuget: DoenaSoft.UnitsOfMeasurement, 1.0.4"
// Install DoenaSoft.UnitsOfMeasurement as a Cake Addin #addin nuget:?package=DoenaSoft.UnitsOfMeasurement&version=1.0.4 // Install DoenaSoft.UnitsOfMeasurement as a Cake Tool #tool nuget:?package=DoenaSoft.UnitsOfMeasurement&version=1.0.4
This package allows the conversion of common SI and American units within the same category (area, energy, length, temperature, time, volume, weight)
All units can be accessed by type name (e.g. Meter) or serializable / SI value (e.g. "m");
Sample conversion from Kilogram to pound:
var lb = new Value<Pound>(1);
var kg = ValueConverter.Convert<Kilogram>(lb).Round(9);
Assert.AreEqual(0.45359237, kg.Scalar);
kg = new Value<Kilogram>(1);
lb = ValueConverter.Convert<Pound>(kg).Round(9);
Assert.AreEqual(2.204622622, lb.Scalar);
It also allows the registration of custom units (i.e not pre-defined in this assembly) with a conversion factor to the category's base unit.
var custom = new CustomWeight(0.0311034768, "oz.tr."); // ounce
UnitConverter.RegisterCustomUnit(custom);
var result = UnitConverter.ToUnitOfMeasurement("oz.tr.");
It also alows the creation of fractional units such as meters per second
var mps = UnitConverter.ToUnitOfMeasurement("m/s");
You can also add values from the same unit category to each other without converting the units first:
var source = new Value<FractionUnit<Meter, Second>>(30);
var target = source.Add(new Value<FractionUnit<Mile, Hour>>(15));
You can also convert between volume and weight units with a given density.
const double DensityOfHelium = 0.1785; // kg/l
var source = new Value(5, UnitConverter.ToUnitOfMeasurement("dm�"));
var target = ValueConverter.Convert(source, new Kilogram(), new DensityValue<Density<Kilogram, Liter>>(DensityOfHelium));
You can even convert values with fractional units where the unit categories are inverted, such as liter per 100 km (volume/length) to gasmileage (length/volume)
var source = new Value<FractionUnit<Liter, Kilometer>>(5.9 / 100);
var target = ValueConverter.Convert(source, new FractionUnit<Mile, USLiquidGallon>()).Round(5); // 39.86688 miles per gallon
More examples can be found in the [unit tests for the project] (https://github.com/DJDoena/DoenaSoft.UnitsOfMeasurement/tree/main/UnitsOfMeasurement.Tests)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 is compatible. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net452 is compatible. net46 is compatible. net461 was computed. net462 is compatible. net463 was computed. net47 is compatible. net471 was computed. net472 is compatible. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 2.2
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETCoreApp 3.1
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETFramework 4.5.2
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETFramework 4.6
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETFramework 4.6.2
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETFramework 4.7
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETFramework 4.7.2
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETFramework 4.8
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 4.5.0)
-
.NETStandard 2.1
- System.ComponentModel.Annotations (>= 4.5.0)
-
net5.0
- System.ComponentModel.Annotations (>= 4.5.0)
-
net6.0
- System.ComponentModel.Annotations (>= 4.5.0)
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.0.2 | 118 | 7/10/2024 |
2.0.1 | 839 | 11/28/2022 |
2.0.0 | 876 | 10/24/2022 |
1.5.3 | 893 | 8/21/2022 |
1.5.2 | 883 | 8/21/2022 |
1.5.1 | 930 | 4/27/2022 |
1.5.0 | 939 | 3/12/2022 |
1.4.0 | 892 | 3/12/2022 |
1.3.0 | 875 | 3/12/2022 |
1.2.2 | 868 | 3/11/2022 |
1.2.1 | 940 | 3/11/2022 |
1.2.0 | 931 | 3/11/2022 |
1.1.1 | 911 | 3/11/2022 |
1.1.0 | 898 | 3/11/2022 |
1.0.5 | 938 | 3/11/2022 |
1.0.4 | 910 | 3/11/2022 |