Skip to content

Commit 5dc45b4

Browse files
authored
Update README.md
Add extension method section
1 parent e56ea9d commit 5dc45b4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ Build Targets:
2020
Overview
2121
---
2222
* [387 units in 36 unit classes](UnitsNet/GeneratedCode/Enums) generated from [JSON](UnitsNet/Scripts/UnitDefinitions/) by [Powershell scripts](UnitsNet/Scripts/GenerateUnits.ps1)
23-
* [826 unit tests](http://teamcity.chump.work/viewType.html?guest=1&buildTypeId=UnitsNet_BuildTest) on conversions and localizations
23+
* [827 unit tests](http://teamcity.chump.work/viewType.html?guest=1&buildTypeId=UnitsNet_BuildTest) on conversions and localizations
2424
* Immutable structs that implement IEquatable, IComparable
2525
* [Static typing](#static-typing) to avoid ambiguous values or units
2626
* [Operator overloads](#operator-overloads) for arithmetic, also between compatible units
27+
* [Extension methods](#extension-methods) for short-hand creation and conversions
2728
* [Parse and ToString()](#culture) supports cultures and localization
2829
* [Enumerate units](#enumerate-units) for user selection
2930
* [Precision and accuracy](#precision)
@@ -66,6 +67,21 @@ Acceleration a2 = Force.FromNewtons(100) / Mass.FromKilograms(20);
6667
RotationalSpeed r = Angle.FromDegrees(90) / TimeSpan.FromSeconds(2);
6768
```
6869

70+
<a name="extension-methods"></a>Extension Methods
71+
---
72+
All units have associated extension methods for a really compact, expressive way to construct values or do arithmetic.
73+
```C#
74+
using UnitsNet.Extensions.NumberToDuration;
75+
using UnitsNet.Extensions.NumberToLength;
76+
using UnitsNet.Extensions.NumberToTimeSpan;
77+
78+
Speed speed = 30.Kilometers() / 1.Hours(); // 30 km/h (using Duration type)
79+
Length distance = speed * 2.h(); // 60 km (using TimeSpan type)
80+
81+
Acceleration stdGravity = 9.80665.MeterPerSecondSquared();
82+
Force weight = 80.Kilograms() * stdGravity; // 80 kilograms-force or 784.532 newtons
83+
```
84+
6985
<a name="culture"></a>Culture and Localization
7086
---
7187
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:

0 commit comments

Comments
 (0)