Skip to content

Commit 5d24432

Browse files
committed
Remove all TODOs in code
Replace with github issues and update comments to point there.
1 parent fb099e4 commit 5d24432

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed

UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ private static object CreateQuantity(Type quantityType, double value, object uni
130130
object quantityValue = GetFromMethodValueArgument(notNullableFromMethod, value);
131131

132132
// Ex: Mass.From(55, MassUnit.Gram)
133-
// TODO: there is a possible loss of precision if base value requires higher precision than double can represent.
134-
// Example: Serializing Information.FromExabytes(100) then deserializing to Information
135-
// will likely return a very different result. Not sure how we can handle this?
133+
// See ValueUnit about precision loss for quantities using decimal type.
136134
return notNullableFromMethod.Invoke(null, new[] {quantityValue, unitValue});
137135
}
138136

@@ -207,7 +205,7 @@ public override void WriteJson(JsonWriter writer, object obj, JsonSerializer ser
207205

208206
serializer.Serialize(writer, new ValueUnit
209207
{
210-
// TODO Should we serialize long, decimal and long differently?
208+
// See ValueUnit about precision loss for quantities using decimal type.
211209
Value = Convert.ToDouble(quantityValue),
212210
Unit = quantityUnitName
213211
});
@@ -233,9 +231,7 @@ private static object GetValueOfQuantity(object value, Type quantityType)
233231
{
234232
FieldInfo valueField = GetPrivateInstanceField(quantityType, ValueFieldName);
235233

236-
// Unit base type can be double, long or decimal,
237-
// so make sure we serialize the real type to avoid
238-
// loss of precision
234+
// See ValueUnit about precision loss for quantities using decimal type.
239235
object quantityValue = valueField.GetValue(value);
240236
return quantityValue;
241237
}
@@ -278,10 +274,13 @@ private static FieldInfo GetPrivateInstanceField(Type quantityType, string field
278274
/// A structure used to serialize/deserialize Units.NET unit instances.
279275
/// </summary>
280276
/// <remarks>
281-
/// TODO Units may use decimal, long or double as base value type and might result
277+
/// Quantities may use decimal, long or double as base value type and this might result
282278
/// in a loss of precision when serializing/deserializing to decimal.
283279
/// Decimal is the highest precision type available in .NET, but has a smaller
284280
/// range than double.
281+
///
282+
/// Json: Support decimal precision #503
283+
/// https://github.com/angularsen/UnitsNet/issues/503
285284
/// </remarks>
286285
private class ValueUnit
287286
{

UnitsNet.Tests/CustomCode/EnergyTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
22
// https://github.com/angularsen/UnitsNet
3-
//
3+
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy
55
// of this software and associated documentation files (the "Software"), to deal
66
// in the Software without restriction, including without limitation the rights
77
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
88
// copies of the Software, and to permit persons to whom the Software is
99
// furnished to do so, subject to the following conditions:
10-
//
10+
//
1111
// The above copyright notice and this permission notice shall be included in
1212
// all copies or substantial portions of the Software.
13-
//
13+
//
1414
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1515
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -23,7 +23,6 @@ namespace UnitsNet.Tests.CustomCode
2323
{
2424
public class EnergyTests : EnergyTestsBase
2525
{
26-
// TODO Override properties in base class here
2726
protected override double ThermsImperialInOneJoule => 9.478171203551087813109937767482e-9;
2827

2928
protected override double JoulesInOneJoule => 1;

UnitsNet.Tests/CustomCode/RotationalStiffnessPerLengthTests.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated (once) by \generate-code.bat, but will not be
4-
// regenerated when it already exists. The purpose of creating this file is to make
4+
// regenerated when it already exists. The purpose of creating this file is to make
55
// it easier to remember to implement all the unit conversion test cases.
6-
//
6+
//
77
// Whenever a new unit is added to this quantity and \generate-code.bat is run,
88
// the base test class will get a new abstract property and cause a compile error
99
// in this derived class, reminding the developer to implement the test case
@@ -20,17 +20,17 @@
2020

2121
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
2222
// https://github.com/angularsen/UnitsNet
23-
//
23+
//
2424
// Permission is hereby granted, free of charge, to any person obtaining a copy
2525
// of this software and associated documentation files (the "Software"), to deal
2626
// in the Software without restriction, including without limitation the rights
2727
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2828
// copies of the Software, and to permit persons to whom the Software is
2929
// furnished to do so, subject to the following conditions:
30-
//
30+
//
3131
// The above copyright notice and this permission notice shall be included in
3232
// all copies or substantial portions of the Software.
33-
//
33+
//
3434
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3535
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3636
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -46,8 +46,6 @@ namespace UnitsNet.Tests.CustomCode
4646
{
4747
public class RotationalStiffnessPerLengthTests : RotationalStiffnessPerLengthTestsBase
4848
{
49-
// TODO Override properties in base class here
50-
5149
protected override double KilonewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter => 1E-3;
5250
protected override double MeganewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter => 1E-6;
5351
protected override double NewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter => 1;

UnitsNet/Scripts/Include-GenerateUnitTestPlaceholderSourceCode.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ function GenerateUnitTestPlaceholderSourceCode($quantity)
55
//------------------------------------------------------------------------------
66
// <auto-generated>
77
// This code was generated (once) by \generate-code.bat, but will not be
8-
// regenerated when it already exists. The purpose of creating this file is to make
8+
// regenerated when it already exists. The purpose of creating this file is to make
99
// it easier to remember to implement all the unit conversion test cases.
10-
//
10+
//
1111
// Whenever a new unit is added to this quantity and \generate-code.bat is run,
1212
// the base test class will get a new abstract property and cause a compile error
1313
// in this derived class, reminding the developer to implement the test case
@@ -24,17 +24,17 @@ function GenerateUnitTestPlaceholderSourceCode($quantity)
2424
2525
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
2626
// https://github.com/angularsen/UnitsNet
27-
//
27+
//
2828
// Permission is hereby granted, free of charge, to any person obtaining a copy
2929
// of this software and associated documentation files (the "Software"), to deal
3030
// in the Software without restriction, including without limitation the rights
3131
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3232
// copies of the Software, and to permit persons to whom the Software is
3333
// furnished to do so, subject to the following conditions:
34-
//
34+
//
3535
// The above copyright notice and this permission notice shall be included in
3636
// all copies or substantial portions of the Software.
37-
//
37+
//
3838
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3939
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4040
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -50,7 +50,7 @@ namespace UnitsNet.Tests.CustomCode
5050
{
5151
public class $($quantityName)Tests : $($quantityName)TestsBase
5252
{
53-
// TODO Override properties in base class here
53+
// Override properties in base class here
5454
}
5555
}
5656
"@;

UnitsNet/UnitConverter.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
22
// https://github.com/angularsen/UnitsNet
3-
//
3+
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy
55
// of this software and associated documentation files (the "Software"), to deal
66
// in the Software without restriction, including without limitation the rights
77
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
88
// copies of the Software, and to permit persons to whom the Software is
99
// furnished to do so, subject to the following conditions:
10-
//
10+
//
1111
// The above copyright notice and this permission notice shall be included in
1212
// all copies or substantial portions of the Software.
13-
//
13+
//
1414
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1515
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -119,8 +119,11 @@ public static bool TryConvertByName(FromValue inputValue, string quantityName, s
119119
{
120120
try
121121
{
122-
// TODO Reimplement to avoid exceptions where possible, as Try methods are generally recommended for performance and this is cheating
122+
// Re-implement this to avoid exceptions where possible, as Try methods are generally recommended for performance and this is cheating.
123123
// https://msdn.microsoft.com/en-us/library/ms229009(v=vs.100).aspx
124+
//
125+
// Implement Try-methods without try-catch #504
126+
// https://github.com/angularsen/UnitsNet/issues/504
124127
result = ConvertByName(inputValue, quantityName, fromUnit, toUnit);
125128
return true;
126129
}
@@ -201,7 +204,7 @@ public static double ConvertByAbbreviation(FromValue fromValue, string quantityN
201204

202205
UnitSystem unitSystem = UnitSystem.GetCached(culture);
203206
object fromUnitValue = unitSystem.Parse(fromUnitAbbrev, unitType); // ex: ("m", LengthUnit) => LengthUnit.Meter
204-
object toUnitValue = unitSystem.Parse(toUnitAbbrev, unitType); // ex:("cm", LengthUnit) => LengthUnit.Centimeter
207+
object toUnitValue = unitSystem.Parse(toUnitAbbrev, unitType); // ex:("cm", LengthUnit) => LengthUnit.Centimeter
205208

206209
MethodInfo fromMethod = GetStaticFromMethod(quantityType, unitType); // ex: UnitsNet.Length.From(double inputValue, LengthUnit inputUnit)
207210
object fromResult = fromMethod.Invoke(null, new[] {fromValue, fromUnitValue}); // ex: Length quantity = UnitsNet.Length.From(5, LengthUnit.Meter)
@@ -277,8 +280,11 @@ public static bool TryConvertByAbbreviation(FromValue fromValue, string quantity
277280
{
278281
try
279282
{
280-
// TODO Reimplement to avoid exceptions where possible, as Try methods are generally recommended for performance and this is cheating
283+
// Re-implement this to avoid exceptions where possible, as Try methods are generally recommended for performance and this is cheating.
281284
// https://msdn.microsoft.com/en-us/library/ms229009(v=vs.100).aspx
285+
//
286+
// Implement Try-methods without try-catch #504
287+
// https://github.com/angularsen/UnitsNet/issues/504
282288
result = ConvertByAbbreviation(fromValue, quantityName, fromUnitAbbrev, toUnitAbbrev, culture);
283289
return true;
284290
}
@@ -373,4 +379,4 @@ private static Type GetQuantityType(string quantityName)
373379
return quantityType;
374380
}
375381
}
376-
}
382+
}

0 commit comments

Comments
 (0)