Skip to content

Commit d1b0c8d

Browse files
authored
Update README.md
1 parent 9a2a5de commit d1b0c8d

File tree

1 file changed

+48
-37
lines changed

1 file changed

+48
-37
lines changed

README.md

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,28 @@ Run the following command in the [Package Manager Console](http://docs.nuget.org
1313
![Install-Package UnitsNet](https://raw.githubusercontent.com/anjdreas/UnitsNet/master/Docs/Images/install_package_unitsnet.png "Install-Package UnitsNet")
1414

1515
Build Targets:
16+
* .NET Standard 1.0
1617
* Portable 4.0 Profile328 (.NET 4, Silverlight 5, Win8, WinPhone8.1 + WP Silverlight 8)
1718
* .NET 3.5 Client
1819

19-
Features
20+
Overview
2021
===
21-
* [370 units of measurement in 35 classes](https://github.com/anjdreas/UnitsNet/tree/master/UnitsNet/GeneratedCode/Enums)
22-
* Generated code for uniform implementations and fewer bugs
23-
* Immutable structs implementing IEquatable, IComparable and operator overloads
24-
* Parse unit abbreviations in multiple cultures
25-
* ToString() variants for custom cultures and format patterns
26-
* Extensible with [custom units](https://github.com/anjdreas/UnitsNet/wiki/Extending-with-Custom-Units)
22+
* [387 units in 36 unit classes](UnitsNet/GeneratedCode/Enums)
23+
* [826 unit tests](http://teamcity.chump.work/viewType.html?guest=1&buildTypeId=UnitsNet_BuildTest) on conversions and localizations
24+
* [Generated code](UnitsNet/GeneratedCode) for uniform implementations and fewer bugs
25+
* Immutable structs that implement IEquatable, IComparable
26+
* [Static typing](#static-typing) to avoid ambiguous values or units
27+
* [Operator overloads](#operator-overloads) for arithmetic, also between compatible units
28+
* [Parse and ToString()](#culture) supports cultures and localization
29+
* [Enumerate units](#enumerate-units) for user selection
30+
* [Precision and accuracy](#precision)
2731
* [Serializable with JSON.NET](https://www.nuget.org/packages/UnitsNet.Serialization.JsonNet)
28-
* 688 unit tests to ensure conversions and localizations are in order
32+
* Extensible with [custom units](https://github.com/anjdreas/UnitsNet/wiki/Extending-with-Custom-Units)
33+
* [Contribute](#contribute) if you are missing some units
34+
* [Continuous integration](#ci) posts status reports to pull requests and commits
35+
* [Who are using this?](#who-are-using)
2936

30-
Static Typing
37+
<a name="static-typing"></a>Static Typing
3138
---
3239
```C#
3340
// Convert to the unit of choice - when you need it
@@ -45,25 +52,22 @@ double feet = meter.Feet; // 3.28084
4552
double inches = meter.Inches; // 39.3701
4653
```
4754

48-
Unit Enumeration
55+
<a name="operator-overloads"></a>Operator Overloads
4956
---
50-
All units have a corresponding unit enum value. This is useful when selecting the unit representation at runtime, such as presenting a choice of units to the user.
5157
```C#
52-
/// <summary>Convert the previous height to the new unit.</summary>
53-
void OnUserChangedHeightUnit(LengthUnit prevUnit, double prevValue, LengthUnit newUnit)
54-
{
55-
// Construct from dynamic unit and value
56-
var prevHeight = Length.From(prevValue, prevUnit);
57-
58-
// Convert to the new unit
59-
double newHeightValue = prevHeight.As(newUnit);
60-
61-
// Update UI with the converted value and the newly selected unit
62-
UpdateHeightUI(newHeightValue, newUnit);
63-
}
58+
// Arithmetic
59+
Length l1 = 2 * Length.FromMeters(1);
60+
Length l2 = Length.FromMeters(1) / 2;
61+
Length l3 = l1 + l2;
62+
63+
// Construct between units
64+
Length distance = Speed.FromKilometersPerHour(80) * TimeSpan.FromMinutes(30);
65+
Acceleration a1 = Speed.FromKilometersPerHour(80) / TimeSpan.FromSeconds(2);
66+
Acceleration a2 = Force.FromNewtons(100) / Mass.FromKilograms(20);
67+
RotationalSpeed r = Angle.FromDegrees(90) / TimeSpan.FromSeconds(2);
6468
```
6569

66-
Culture and Localization
70+
<a name="culture"></a>Culture and Localization
6771
---
6872
The culture for abbreviations defaults to Thread.CurrentUICulture and falls back to US English if not defined. Thread.CurrentCulture affects number formatting unless a custom culture is specified. The relevant methods are:
6973

@@ -96,15 +100,25 @@ RotationalSpeedUnit.RevolutionPerMinute == RotationalSpeed.ParseUnit("r/min");
96100
"kg" == Mass.GetAbbreviation(MassUnit.Kilogram);
97101
```
98102

99-
Helper Construction Methods
103+
<a name="enumerate-units"></a>Enumerate Units
100104
---
101-
Construct measurements with various helper methods for convenience and readability.
105+
All units have a unit enum value. Let the user decide what unit of measurement to present the numbers in.
102106
```C#
103-
Force.FromPressureByArea(Pressure p, Length2d area)
104-
Force.FromMassAcceleration(Mass mass, double metersPerSecondSquared)
107+
/// <summary>Convert the previous height to the new unit.</summary>
108+
void OnUserChangedHeightUnit(LengthUnit prevUnit, double prevValue, LengthUnit newUnit)
109+
{
110+
// Construct from dynamic unit and value
111+
var prevHeight = Length.From(prevValue, prevUnit);
112+
113+
// Convert to the new unit
114+
double newHeightValue = prevHeight.As(newUnit);
115+
116+
// Update UI with the converted value and the newly selected unit
117+
UpdateHeightUI(newHeightValue, newUnit);
118+
}
105119
```
106120

107-
Precision and Accuracy
121+
<a name="precision"></a>Precision and Accuracy
108122
===
109123
A base unit is chosen for each unit class, represented by a double value (64-bit), and all conversions go via this unit. This means there will always be a small error in both representing other units than the base unit as well as converting between units.
110124

@@ -114,7 +128,8 @@ The tests accept an error up to 1E-5 for most units added so far. Exceptions inc
114128

115129
For more details, see [Precision](https://github.com/anjdreas/UnitsNet/wiki/Precision).
116130

117-
Serialization
131+
132+
<a name="serialization"></a>Serialization
118133
===
119134
* `UnitsNet.Serialization.JsonNet` ([nuget](https://www.nuget.org/packages/UnitsNet.Serialization.JsonNet), [src](https://github.com/anjdreas/UnitsNet/tree/master/UnitsNet.Serialization.JsonNet), [tests](https://github.com/anjdreas/UnitsNet/tree/master/UnitsNet.Serialization.JsonNet.Tests)) for JSON.NET
120135

@@ -123,12 +138,8 @@ We cannot guarantee backwards compatibility, although we will strive to do that
123138

124139
The base unit of any unit should be be treated as volatile as we have changed this several times in the history of this library already. Either to reduce precision errors of common units or to simplify code generation. An example is Mass, where the base unit was first Kilogram as this is the SI unit of mass, but in order to use powershell scripts to generate milligrams, nanograms etc. it was easier to choose Gram as the base unit of Mass.
125140

126-
What It Is Not
127-
===
128-
* It is not an equation solver
129-
* It does not figure out the units after a calculation
130141

131-
Want To Contribute?
142+
<a name="contribute"></a>Want To Contribute?
132143
==
133144
This project is still early and many units and conversions are not yet covered. If you are missing something, please help by contributing or [ask for it](https://github.com/anjdreas/UnitsNet/issues) by creating an issue.
134145

@@ -140,13 +151,13 @@ Generally adding a unit involves adding or modifying `UnitsNet\Scripts\UnitDefin
140151
* Do work on branches such as **feature/add-myunit** and **fix/34**
141152
* [Create a pull request](https://help.github.com/articles/using-pull-requests)
142153

143-
Continuous Integration
154+
<a name="ci"></a>Continuous Integration
144155
===
145156
A [TeamCity build server](http://teamcity.chump.work/viewType.html?buildTypeId=UnitsNet&guest=1) performs the following:
146157
* Build and test pull requests. Notifies on success or error.
147158
* Build, test and deploy nuget on master branch.
148159

149-
Who are Using This?
160+
<a name="who-are-using"></a>Who are Using This?
150161
===
151162
It would be awesome to know who are using this library. If you would like your project listed here, [create an issue](https://github.com/anjdreas/UnitsNet/issues) or edit the [README.md](https://github.com/anjdreas/UnitsNet/edit/master/README.md) and send a pull request. Max logo size is `300x35 pixels` and should be in `.png`, `.gif` or `.jpg` formats.
152163

0 commit comments

Comments
 (0)