-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- new units - tipographical points and picas, troy oz, metric, uk and…
… us tonne. new method of class creation unit.New(v) and conversion to and from tuples
- Loading branch information
1 parent
f4481b6
commit 05ea59f
Showing
13 changed files
with
270 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Gehtsoft.Measurements | ||
{ | ||
/// <summary> | ||
/// The extensions for unit type enumerations | ||
/// </summary> | ||
public static class UnitExtensions | ||
{ | ||
/// <summary> | ||
/// <para>Creates a new value of the specified unit.</para> | ||
/// <para>The method is an extension for a `enum` value, i.e. you can use it as `AngularUnit.MOA.New(10)` instead of writing `new Measurement<AngularUnit>(10, AngularUnit.MOA)`</para> | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="unit"></param> | ||
/// <param name="value"></param> | ||
/// <returns></returns> | ||
public static Measurement<T> New<T>(this T unit, double value) where T : Enum => new Measurement<T>(value, unit); | ||
|
||
/// <summary> | ||
/// Converts an enumeration of doubles into an enumeration of measures of the specified unit. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="values"></param> | ||
/// <param name="unit"></param> | ||
/// <returns></returns> | ||
public static IEnumerable<Measurement<T>> As<T>(this IEnumerable<double> values, T unit) where T : Enum | ||
{ | ||
foreach (var v in values) | ||
yield return new Measurement<T>(v, unit); | ||
} | ||
} | ||
} |
Oops, something went wrong.