Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CodeGen/Generators/QuantityRelationsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class QuantityRelationsParser
/// The relations are defined in UnitRelations.json
/// Each defined relation can be applied multiple times to one or two quantities depending on the operator and the operands.
///
/// The format of a relation definition is "Quantity.Unit operator Quantity.Unit = Quantity.Unit" (See examples below).
/// The format of a relation definition is "Quantity.Unit = Quantity.Unit * Quantity.Unit" (See examples below).
/// "double" can be used as a unitless operand.
/// "1" can be used as the result operand to define inverse relations.
///
Expand Down Expand Up @@ -82,8 +82,8 @@ public static void ParseAndApplyRelations(string rootDir, Quantity[] quantities)
relations.Sort();

var duplicates = relations
.GroupBy(r => r.SortString)
.Where(g => g.Count() > 1)
.CountBy(r => r.SortString)
.Where(g => g.Value > 1)
.Select(g => g.Key)
.ToList();

Expand All @@ -94,8 +94,8 @@ public static void ParseAndApplyRelations(string rootDir, Quantity[] quantities)
}

var ambiguous = relations
.GroupBy(r => $"{r.LeftQuantity.Name} {r.Operator} {r.RightQuantity.Name}")
.Where(g => g.Count() > 1)
.CountBy(r => r.DisambiguationString)
.Where(g => g.Value > 1)
.Select(g => g.Key)
.ToList();

Expand Down
17 changes: 8 additions & 9 deletions CodeGen/JsonTypes/QuantityRelation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ internal record QuantityRelation : IComparable<QuantityRelation>
public Quantity ResultQuantity = null!;
public Unit ResultUnit = null!;

public string SortString => ResultQuantity.Name + PrependDot(ResultUnit.SingularName)
+ " = "
+ LeftQuantity.Name + PrependDot(LeftUnit.SingularName)
+ " " + Operator + " "
+ RightQuantity.Name + PrependDot(RightUnit.SingularName);
public string DisambiguationString => $"{LeftQuantity.Name} {Operator} {RightQuantity.Name}";

public string SortString => string.Concat(
ResultQuantity.Name, ResultUnit.SingularName,
LeftQuantity.Name, LeftUnit.SingularName, Operator,
RightQuantity.Name, RightUnit.SingularName);

public int CompareTo(QuantityRelation? other)
{
return string.Compare(SortString, other?.SortString, StringComparison.Ordinal);
return string.Compare(SortString, other?.SortString, StringComparison.OrdinalIgnoreCase);
}

private static string PrependDot(string? s) => s == null ? string.Empty : "." + s;
}
}
}
14 changes: 7 additions & 7 deletions UnitsNet/GeneratedCode/Quantities/Area.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions UnitsNet/GeneratedCode/Quantities/Density.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions UnitsNet/GeneratedCode/Quantities/Length.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions UnitsNet/GeneratedCode/Quantities/Mass.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading