Skip to content

Commit 2afcfed

Browse files
authored
Add IQuantity.Value (#612)
* Add IQuantity.Value Value type double as is the standard contract for conversion property getters, until we add support for different value types.
1 parent bff52c0 commit 2afcfed

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/IQuantity.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace UnitsNet
2828
/// <summary>
2929
/// Represents a quantity.
3030
/// </summary>
31-
public partial interface IQuantity
31+
public interface IQuantity
3232
{
3333
/// <summary>
3434
/// The <see cref="QuantityType" /> of this quantity.
@@ -58,6 +58,11 @@ public partial interface IQuantity
5858
/// </summary>
5959
Enum Unit { get; }
6060

61+
/// <summary>
62+
/// The value this quantity was constructed with. Should be seen in combination with <see cref="Unit"/>.
63+
/// </summary>
64+
double Value { get; }
65+
6166
/// <summary>
6267
/// Change the default unit representation of the quantity, which affects things like <see cref="IQuantity.ToString(System.IFormatProvider)"/>.
6368
/// </summary>

UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ function GenerateProperties([GeneratorArgs]$genArgs)
348348
{
349349
$quantityName = $genArgs.Quantity.Name
350350
$unitEnumName = $genArgs.UnitEnumName
351-
$baseUnitSingularName = $genArgs.BaseUnit.SingularName
352351
$valueType = $genArgs.Quantity.BaseType
352+
[bool]$isDoubleValueType = $valueType -eq "double"
353353
@"
354354
355355
#region Properties
@@ -359,6 +359,10 @@ function GenerateProperties([GeneratorArgs]$genArgs)
359359
/// </summary>
360360
public $valueType Value => _value;
361361
362+
"@; if (-not $isDoubleValueType) { @"
363+
double IQuantity.Value => (double) _value;
364+
365+
"@; } @"
362366
/// <inheritdoc cref="IQuantity.Unit"/>
363367
Enum IQuantity.Unit => Unit;
364368

0 commit comments

Comments
 (0)