Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Add extension method section
  • Loading branch information
angularsen authored Oct 23, 2016
1 parent e56ea9d commit 5dc45b4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ Build Targets:
Overview
---
* [387 units in 36 unit classes](UnitsNet/GeneratedCode/Enums) generated from [JSON](UnitsNet/Scripts/UnitDefinitions/) by [Powershell scripts](UnitsNet/Scripts/GenerateUnits.ps1)
* [826 unit tests](http://teamcity.chump.work/viewType.html?guest=1&buildTypeId=UnitsNet_BuildTest) on conversions and localizations
* [827 unit tests](http://teamcity.chump.work/viewType.html?guest=1&buildTypeId=UnitsNet_BuildTest) on conversions and localizations
* Immutable structs that implement IEquatable, IComparable
* [Static typing](#static-typing) to avoid ambiguous values or units
* [Operator overloads](#operator-overloads) for arithmetic, also between compatible units
* [Extension methods](#extension-methods) for short-hand creation and conversions
* [Parse and ToString()](#culture) supports cultures and localization
* [Enumerate units](#enumerate-units) for user selection
* [Precision and accuracy](#precision)
Expand Down Expand Up @@ -66,6 +67,21 @@ Acceleration a2 = Force.FromNewtons(100) / Mass.FromKilograms(20);
RotationalSpeed r = Angle.FromDegrees(90) / TimeSpan.FromSeconds(2);
```

<a name="extension-methods"></a>Extension Methods
---
All units have associated extension methods for a really compact, expressive way to construct values or do arithmetic.
```C#
using UnitsNet.Extensions.NumberToDuration;
using UnitsNet.Extensions.NumberToLength;
using UnitsNet.Extensions.NumberToTimeSpan;

Speed speed = 30.Kilometers() / 1.Hours(); // 30 km/h (using Duration type)
Length distance = speed * 2.h(); // 60 km (using TimeSpan type)
Acceleration stdGravity = 9.80665.MeterPerSecondSquared();
Force weight = 80.Kilograms() * stdGravity; // 80 kilograms-force or 784.532 newtons
```

<a name="culture"></a>Culture and Localization
---
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:
Expand Down

4 comments on commit 5dc45b4

@angularsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Units.NET :: Build and Test Build 204 is now running

@angularsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Units.NET :: Build and Test Build 204 outcome was SUCCESS
Summary: Tests passed: 827 Build time: 0:0:28

@angularsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Units.NET :: Publish NuGets Build 204 is now running

@angularsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Units.NET :: Publish NuGets Build 204 outcome was SUCCESS
Summary: Running Build time: 0:0:13

Please sign in to comment.