Skip to content

Commit 04f233c

Browse files
authored
Fix QuantityTypes and UnitTypes fields
They included more types than they should.
1 parent dc69270 commit 04f233c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

UnitsNet/UnitConverter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ public static class UnitConverter
4646
private static readonly Assembly UnitsNetAssembly = typeof(Length).GetAssembly();
4747

4848
private static readonly Type[] QuantityTypes = UnitsNetAssembly.GetTypes()
49-
.Where(x => x.FullName.StartsWith(QuantityNamespace))
49+
.Where(typeof(IQuantity).IsAssignableFrom)
50+
.Where(x => x.IsClass || x.IsValueType) // Future-proofing: we are discussing changing quantities from struct to class
5051
.ToArray();
5152

5253
private static readonly Type[] UnitTypes = UnitsNetAssembly.GetTypes()
53-
.Where(x => x.FullName.StartsWith(UnitTypeNamespace))
54+
.Where(x => x.Namespace == UnitTypeNamespace && x.IsEnum && x.Name.EndsWith("Unit"))
5455
.ToArray();
5556

5657
/// <summary>

0 commit comments

Comments
 (0)