Skip to content

Commit 9d734de

Browse files
angularsenclaude
andcommitted
Option A: Add implicit QuantityValue → double conversion
Change explicit operator double(QuantityValue) to implicit. This eliminates the largest consumer-facing breaking change in PR #1544. Library code: zero changes needed beyond the operator keyword. Test code: 101 Assert.Equal calls needed (double) cast to resolve xUnit overload ambiguity — a mechanical fix, not a behavioral change. Build: 0 errors, 0 warnings. Tests: all pass (4 pre-existing failures unrelated to this change). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 528a7a8 commit 9d734de

29 files changed

+135
-135
lines changed

UnitsNet.Serialization.JsonNet.Tests/AbbreviatedUnitsConverterTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Text;
44
using Newtonsoft.Json;
@@ -154,7 +154,7 @@ public void DoubleIQuantity_DeserializedFromDoubleValueAndAbbreviatedUnit()
154154

155155
var quantity = DeserializeObject<IQuantity>(json);
156156

157-
Assert.Equal(1.2, quantity.Value);
157+
Assert.Equal(1.2, (double)quantity.Value);
158158
Assert.Equal(MassUnit.Milligram, quantity.Unit);
159159
}
160160

@@ -177,7 +177,7 @@ public void DoubleQuantity_DeserializedFromDoubleValueAndAbbreviatedUnit()
177177

178178
var quantity = DeserializeObject<Mass>(json);
179179

180-
Assert.Equal(1.2, quantity.Value);
180+
Assert.Equal(1.2, (double)quantity.Value);
181181
Assert.Equal(MassUnit.Milligram, quantity.Unit);
182182
}
183183

@@ -188,7 +188,7 @@ public void DoubleIQuantity_DeserializedFromDoubleValueAndNonAmbiguousAbbreviate
188188

189189
var quantity = DeserializeObject<IQuantity>(json);
190190

191-
Assert.Equal(1.2, quantity.Value);
191+
Assert.Equal(1.2, (double)quantity.Value);
192192
Assert.Equal(MassUnit.EarthMass, quantity.Unit);
193193
}
194194

@@ -199,7 +199,7 @@ public void DoubleIQuantity_DeserializedFromDoubleValueAndAbbreviatedUnit_CaseIn
199199

200200
var quantity = DeserializeObject<IQuantity>(json);
201201

202-
Assert.Equal(1.2, quantity.Value);
202+
Assert.Equal(1.2, (double)quantity.Value);
203203
Assert.Equal(MassUnit.Milligram, quantity.Unit);
204204
}
205205

@@ -211,8 +211,8 @@ public void DoubleIQuantity_DeserializedFromDoubleValueAndAbbreviatedUnit_CaseSe
211211
var megabar = DeserializeObject<IQuantity>(json);
212212
var millibar = DeserializeObject<IQuantity>(json.ToLower());
213213

214-
Assert.Equal(1.2, megabar.Value);
215-
Assert.Equal(1.2, millibar.Value);
214+
Assert.Equal(1.2, (double)megabar.Value);
215+
Assert.Equal(1.2, (double)millibar.Value);
216216
Assert.Equal(PressureUnit.Megabar, megabar.Unit);
217217
Assert.Equal(PressureUnit.Millibar, millibar.Unit);
218218
}
@@ -224,7 +224,7 @@ public void Converter_IgnoresUnknownProperties()
224224

225225
var quantity = DeserializeObject<IQuantity>(json);
226226

227-
Assert.Equal(1.2, quantity.Value);
227+
Assert.Equal(1.2, (double)quantity.Value);
228228
Assert.Equal(MassUnit.Milligram, quantity.Unit);
229229
}
230230

@@ -294,7 +294,7 @@ public void DoubleIQuantity_DeserializedFromQuotedDoubleValueAndAbbreviatedUnit(
294294

295295
var quantity = DeserializeObject<IQuantity>(json);
296296

297-
Assert.Equal(1.2, quantity.Value);
297+
Assert.Equal(1.2, (double)quantity.Value);
298298
Assert.Equal(MassUnit.Milligram, quantity.Unit);
299299
}
300300

@@ -305,7 +305,7 @@ public void DoubleQuantity_DeserializedFromQuotedDoubleValueAndAbbreviatedUnit()
305305

306306
var quantity = DeserializeObject<Mass>(json);
307307

308-
Assert.Equal(1.2, quantity.Value);
308+
Assert.Equal(1.2, (double)quantity.Value);
309309
Assert.Equal(MassUnit.Milligram, quantity.Unit);
310310
}
311311

@@ -338,7 +338,7 @@ public void DoubleBaseUnitQuantity_DeserializedFromValueAndNoUnit()
338338

339339
var quantity = DeserializeObject<IQuantity>(json);
340340

341-
Assert.Equal(1.2, quantity.Value);
341+
Assert.Equal(1.2, (double)quantity.Value);
342342
Assert.Equal(Mass.BaseUnit, quantity.Unit);
343343
}
344344

@@ -349,7 +349,7 @@ public void DoubleBaseUnitIQuantity_DeserializedFromValueAndNoUnit()
349349

350350
var quantity = DeserializeObject<Mass>(json);
351351

352-
Assert.Equal(1.2, quantity.Value);
352+
Assert.Equal(1.2, (double)quantity.Value);
353353
Assert.Equal(Mass.BaseUnit, quantity.Unit);
354354
}
355355

UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed under MIT No Attribution, see LICENSE file at the root.
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using System;
@@ -118,7 +118,7 @@ public void UnitsNetIQuantityJsonConverter_ReadJson_works_as_expected()
118118

119119
Assert.NotNull(result);
120120
Assert.IsType<Power>(result);
121-
Assert.Equal(10.3654, ((Power)result).Watts);
121+
Assert.Equal(10.3654, (double)((Power)result).Watts);
122122
}
123123
}
124124
}

UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonDeserializationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed under MIT No Attribution, see LICENSE file at the root.
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using Newtonsoft.Json;
@@ -296,7 +296,7 @@ public void CanDeserializeDoubleQuantityJson()
296296
""";
297297

298298
Length deserialized = DeserializeObject<Length>(json);
299-
Assert.Equal(10.5, deserialized.Value);
299+
Assert.Equal(10.5, (double)deserialized.Value);
300300
Assert.Equal(LengthUnit.Centimeter, deserialized.Unit);
301301
}
302302

@@ -324,7 +324,7 @@ public void CanDeserializeLegacyDecimalQuantityJson()
324324
""";
325325

326326
Information deserialized = DeserializeObject<Information>(json);
327-
Assert.Equal(10.5, deserialized.Value);
327+
Assert.Equal(10.5, (double)deserialized.Value);
328328
Assert.Equal(InformationUnit.Kilobyte, deserialized.Unit);
329329
}
330330

UnitsNet.Tests/AffineQuantityExtensionsTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed under MIT No Attribution, see LICENSE file at the root.
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using UnitsNet.Tests.CustomQuantities;
@@ -131,7 +131,7 @@ public void Average_Temperature(double[] values, double expectedAverage)
131131

132132
Temperature result = temperatures.Average();
133133

134-
Assert.Equal(expectedAverage, result.Value);
134+
Assert.Equal(expectedAverage, (double)result.Value);
135135
Assert.Equal(TemperatureUnit.DegreeCelsius, result.Unit);
136136
}
137137

@@ -176,7 +176,7 @@ public void Average_Temperature_WithUnit(double[] values, TemperatureUnit unit,
176176

177177
Temperature result = temperatures.Average(unit);
178178

179-
Assert.Equal(expectedAverage, result.Value);
179+
Assert.Equal(expectedAverage, (double)result.Value);
180180
Assert.Equal(unit, result.Unit);
181181
}
182182

UnitsNet.Tests/ConversionExpressionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed under MIT No Attribution, see LICENSE file at the root.
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using System.Text;
@@ -105,7 +105,7 @@ public void Evaluate_Value_ReturnsExpectedResult(double coefficient, int exponen
105105
{
106106
var expression = new ConversionExpression(coefficient, null, exponent, constantTerm);
107107
QuantityValue result = expression.Evaluate(value);
108-
Assert.Equal(expected, result);
108+
Assert.Equal(expected, (double)result);
109109
}
110110

111111
[Theory]
@@ -118,7 +118,7 @@ public void Evaluate_Value_WithNestedFunction_ReturnsExpectedResult(double coeff
118118
{
119119
var expression = new ConversionExpression(coefficient, quantityValue => -quantityValue / 2, exponent, constantTerm);
120120
QuantityValue result = expression.Evaluate(value);
121-
Assert.Equal(expected, result);
121+
Assert.Equal(expected, (double)result);
122122
}
123123

124124
[Theory]

UnitsNet.Tests/CustomCode/AmplitudeRatioTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed under MIT No Attribution, see LICENSE file at the root.
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using System;
@@ -51,7 +51,7 @@ public void ExpectVoltageConvertedToAmplitudeRatioCorrectly(double voltage, doub
5151
ElectricPotential v = ElectricPotential.FromVolts(voltage);
5252

5353
var actual = AmplitudeRatio.FromElectricPotential(v).DecibelVolts;
54-
Assert.Equal(expected, actual);
54+
Assert.Equal(expected, (double)actual);
5555
}
5656

5757
[Theory]
@@ -66,7 +66,7 @@ public void ExpectAmplitudeRatioConvertedToVoltageCorrectly(double amplitudeRati
6666
AmplitudeRatio ar = AmplitudeRatio.FromDecibelVolts(amplitudeRatio);
6767

6868
var actual = ar.ToElectricPotential().Volts;
69-
Assert.Equal(expected, actual);
69+
Assert.Equal(expected, (double)actual);
7070
}
7171

7272
// http://www.maximintegrated.com/en/app-notes/index.mvp/id/808

UnitsNet.Tests/CustomCode/AreaDensityTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated (once) by \generate-code.bat, but will not be
44
// regenerated when it already exists. The purpose of creating this file is to make
@@ -38,7 +38,7 @@ public class AreaDensityTests : AreaDensityTestsBase
3838
public void AreaDensityTimesAreaEqualsMass()
3939
{
4040
Mass massOfOneA4Paper = AreaDensity.FromGramsPerSquareMeter(120) * Area.FromSquareCentimeters(625);
41-
Assert.Equal(7.5, massOfOneA4Paper.Grams);
41+
Assert.Equal(7.5, (double)massOfOneA4Paper.Grams);
4242
}
4343
}
4444
}

UnitsNet.Tests/CustomCode/AreaTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed under MIT No Attribution, see LICENSE file at the root.
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using UnitsNet.Units;
@@ -110,7 +110,7 @@ public void Constructor_UnitSystemSI_AssignsSIUnit()
110110
public void As_GivenSIUnitSystem_ReturnsSIValue()
111111
{
112112
var squareInches = new Area(2.0, AreaUnit.SquareInch);
113-
Assert.Equal(0.00129032, squareInches.As(UnitSystem.SI));
113+
Assert.Equal(0.00129032, (double)squareInches.As(UnitSystem.SI));
114114
}
115115

116116
[Fact]
@@ -120,7 +120,7 @@ public void ToUnit_GivenSIUnitSystem_ReturnsSIQuantity()
120120

121121
var inSI = squareInches.ToUnit(UnitSystem.SI);
122122

123-
Assert.Equal(0.00129032, inSI.Value);
123+
Assert.Equal(0.00129032, (double)inSI.Value);
124124
Assert.Equal(AreaUnit.SquareMeter, inSI.Unit);
125125
}
126126

@@ -134,14 +134,14 @@ public void InverseReturnsReciprocalArea(double value, double expected)
134134
{
135135
var area = new Area(value, AreaUnit.SquareMeter);
136136
var inverseArea = area.Inverse();
137-
Assert.Equal(expected, inverseArea.InverseSquareMeters);
137+
Assert.Equal(expected, (double)inverseArea.InverseSquareMeters);
138138
}
139139

140140
[Fact]
141141
public void AreaTimesReciprocalAreaEqualsRatio()
142142
{
143143
Ratio ratio = Area.FromSquareMeters(0.5) * ReciprocalArea.FromInverseSquareMeters(10);
144-
Assert.Equal(5.0, ratio.Value);
144+
Assert.Equal(5.0, (double)ratio.Value);
145145
}
146146

147147
[Fact]

UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated (once) by \generate-code.bat, but will not be
44
// regenerated when it already exists. The purpose of creating this file is to make
@@ -47,7 +47,7 @@ public static void InverseTest( double value, double expected )
4747
var unit = new ElectricConductivity( value, ElectricConductivityUnit.SiemensPerMeter );
4848
var inverse = unit.Inverse();
4949

50-
Assert.Equal( expected, inverse.OhmMeters );
50+
Assert.Equal( expected, (double)inverse.OhmMeters );
5151
}
5252
}
5353
}

UnitsNet.Tests/CustomCode/ElectricResistivityTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated (once) by \generate-code.bat, but will not be
44
// regenerated when it already exists. The purpose of creating this file is to make
@@ -68,7 +68,7 @@ public static void InverseTest( double value, double expected )
6868
var unit = new ElectricResistivity( value, ElectricResistivityUnit.OhmMeter );
6969
var inverse = unit.Inverse();
7070

71-
Assert.Equal( expected, inverse.SiemensPerMeter );
71+
Assert.Equal( expected, (double)inverse.SiemensPerMeter );
7272
}
7373
}
7474
}

0 commit comments

Comments
 (0)