Skip to content

Commit

Permalink
[WIP] Don't call object.Equals() from '=='-operators but use Equals i…
Browse files Browse the repository at this point in the history
…mplementations on the type.
  • Loading branch information
danielcweber committed Aug 13, 2024
1 parent 88f00f3 commit 4fcf784
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Vogen/GenerateEqualsMethodsAndOperators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public static string GenerateEqualsOperatorsForPrimitivesIfNeeded(string itemUnd
if (item.Config.PrimitiveEqualityGeneration.HasFlag(PrimitiveEqualityGeneration.GenerateOperators))
return $"""
public static global::System.Boolean operator ==({typeName} left, {itemUnderlyingType} right) => Equals(left.Value, right);
public static global::System.Boolean operator !=({typeName} left, {itemUnderlyingType} right) => !Equals(left.Value, right);
public static global::System.Boolean operator ==({typeName} left, {itemUnderlyingType} right) => left.Equals(right);
public static global::System.Boolean operator !=({typeName} left, {itemUnderlyingType} right) => !(left == right);
public static global::System.Boolean operator ==({itemUnderlyingType} left, {typeName} right) => Equals(left, right.Value);
public static global::System.Boolean operator !=({itemUnderlyingType} left, {typeName} right) => !Equals(left, right.Value);
public static global::System.Boolean operator ==({itemUnderlyingType} left, {typeName} right) => right.Equals(left);
public static global::System.Boolean operator !=({itemUnderlyingType} left, {typeName} right) => !(left == right);
""";

return string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/Generators/StructGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public readonly {itemUnderlyingType} Value
}}
{GenerateEqualsMethodsAndOperators.GenerateEqualsMethodsForAStruct(item, tds)}
public static global::System.Boolean operator ==({structName} left, {structName} right) => Equals(left, right);
public static global::System.Boolean operator ==({structName} left, {structName} right) => left.Equals(right);
public static global::System.Boolean operator !=({structName} left, {structName} right) => !(left == right);
{GenerateEqualsMethodsAndOperators.GenerateEqualsOperatorsForPrimitivesIfNeeded(itemUnderlyingType, structName, item)}
Expand Down

0 comments on commit 4fcf784

Please sign in to comment.