From b73923fcb62b41fcce9e2d2efa5af6c9eb91915e Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sat, 23 Feb 2019 13:45:20 +0100 Subject: [PATCH 1/3] Add IQuantity.Value Value type double as is the standard contract for conversion property getters, until we add support for different value types. --- UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs | 2 ++ .../GeneratedCode/Quantities/Information.NetFramework.g.cs | 2 ++ UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs | 2 ++ UnitsNet/IQuantity.cs | 4 +++- UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 | 6 +++++- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs index 14edd9e1bf..95fe314fdb 100644 --- a/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs @@ -134,6 +134,8 @@ public BitRate(decimal numericValue, BitRateUnit unit) /// public decimal Value => _value; + double IQuantity.Value => (double)_value; + /// Enum IQuantity.Unit => Unit; diff --git a/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs index 3f6d0dc384..f851743867 100644 --- a/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs @@ -131,6 +131,8 @@ public Information(decimal numericValue, InformationUnit unit) /// public decimal Value => _value; + double IQuantity.Value => (double)_value; + /// Enum IQuantity.Unit => Unit; diff --git a/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs index e768a314f7..36f1abd57e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs @@ -131,6 +131,8 @@ public Power(decimal numericValue, PowerUnit unit) /// public decimal Value => _value; + double IQuantity.Value => (double) _value; + /// Enum IQuantity.Unit => Unit; diff --git a/UnitsNet/IQuantity.cs b/UnitsNet/IQuantity.cs index 88498c2624..413eaeea77 100644 --- a/UnitsNet/IQuantity.cs +++ b/UnitsNet/IQuantity.cs @@ -28,7 +28,7 @@ namespace UnitsNet /// /// Represents a quantity. /// - public partial interface IQuantity + public interface IQuantity { /// /// The of this quantity. @@ -58,6 +58,8 @@ public partial interface IQuantity /// Enum Unit { get; } + double Value { get; } + /// /// Change the default unit representation of the quantity, which affects things like . /// diff --git a/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 b/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 index 5cc4e7ff14..8634d84904 100644 --- a/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 +++ b/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 @@ -348,8 +348,8 @@ function GenerateProperties([GeneratorArgs]$genArgs) { $quantityName = $genArgs.Quantity.Name $unitEnumName = $genArgs.UnitEnumName - $baseUnitSingularName = $genArgs.BaseUnit.SingularName $valueType = $genArgs.Quantity.BaseType + [bool]$isDoubleValueType = $valueType -eq "double" @" #region Properties @@ -359,6 +359,10 @@ function GenerateProperties([GeneratorArgs]$genArgs) /// public $valueType Value => _value; +"@; if (-not $isDoubleValueType) { @" + double IQuantity.Value => (double) _value; + +"@; } @" /// Enum IQuantity.Unit => Unit; From 28c82358ffbf4fc279e4986dc23cde285c1d5068 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sat, 23 Feb 2019 13:48:08 +0100 Subject: [PATCH 2/3] Regen to fix formatting --- UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs | 2 +- UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs index 95fe314fdb..b363c11d0b 100644 --- a/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs @@ -134,7 +134,7 @@ public BitRate(decimal numericValue, BitRateUnit unit) /// public decimal Value => _value; - double IQuantity.Value => (double)_value; + double IQuantity.Value => (double) _value; /// Enum IQuantity.Unit => Unit; diff --git a/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs index f851743867..088d117102 100644 --- a/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs @@ -131,7 +131,7 @@ public Information(decimal numericValue, InformationUnit unit) /// public decimal Value => _value; - double IQuantity.Value => (double)_value; + double IQuantity.Value => (double) _value; /// Enum IQuantity.Unit => Unit; From 02bec8d069cfd87e6c0a879f8e1ccb558f55519d Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sat, 23 Feb 2019 13:49:37 +0100 Subject: [PATCH 3/3] Add xmldoc --- UnitsNet/IQuantity.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UnitsNet/IQuantity.cs b/UnitsNet/IQuantity.cs index 413eaeea77..569d20ca01 100644 --- a/UnitsNet/IQuantity.cs +++ b/UnitsNet/IQuantity.cs @@ -58,6 +58,9 @@ public interface IQuantity /// Enum Unit { get; } + /// + /// The value this quantity was constructed with. Should be seen in combination with . + /// double Value { get; } ///