diff --git a/bindgen/templates/ObjectTemplate.cs b/bindgen/templates/ObjectTemplate.cs index 18db7b9..c488ef1 100644 --- a/bindgen/templates/ObjectTemplate.cs +++ b/bindgen/templates/ObjectTemplate.cs @@ -82,16 +82,6 @@ public override bool Equals(object? obj) if (obj is null || !(obj is {{type_name}})) return false; return Equals(obj as {{type_name}}); } - public static bool operator == ({{type_name}}? a, {{type_name}}? b) - { - if (a is null || b is null) return Object.Equals(a, b); - return a.Equals(b); - } - public static bool operator != ({{type_name}}? a, {{type_name}}? b) - { - if (a is null || b is null) return !Object.Equals(a, b); - return !(a.Equals(b)); - } {%- when UniffiTrait::Hash { hash } %} public override int GetHashCode() { return (int){{ Type::UInt64.borrow()|lift_fn }}({%- call cs::to_ffi_call_with_prefix("this.GetHandle()", hash) %}); diff --git a/dotnet-tests/UniffiCS.BindingTests/TestTraitMethod.cs b/dotnet-tests/UniffiCS.BindingTests/TestTraitMethod.cs index b6aee35..2f53b9b 100644 --- a/dotnet-tests/UniffiCS.BindingTests/TestTraitMethod.cs +++ b/dotnet-tests/UniffiCS.BindingTests/TestTraitMethod.cs @@ -24,20 +24,17 @@ public void TestEq() { using (var methods = new TraitMethods("yo")) { + // Values are equal if input is the same Assert.Equal(methods, new TraitMethods("yo")); - Assert.True(methods == new TraitMethods("yo")); - - Assert.Equal(methods, methods); - Assert.NotEqual(methods, new TraitMethods("yoyo")); - Assert.True(methods != new TraitMethods("yoyo")); - } - Assert.False(new TraitMethods("yo") == null); + // Values are not referentially equal + Assert.False(methods == new TraitMethods("yo")); + } } [Fact] - public void TestEqNulls() + public void TestEqNull() { TraitMethods? t1 = null; TraitMethods? t2 = null; @@ -54,8 +51,10 @@ public void TestEqNulls() public void TestEqContains() { var tm = new TraitMethods("yo"); - var list = new List(); - list.Add(tm); + var list = new List + { + tm + }; Assert.Contains(tm, list); Assert.Contains(new TraitMethods("yo"), list); @@ -90,20 +89,17 @@ public void TestEq() { using (var methods = new ProcTraitMethods("yo")) { + // Values are equal if input is the same Assert.Equal(methods, new ProcTraitMethods("yo")); - Assert.True(methods == new ProcTraitMethods("yo")); - - Assert.Equal(methods, methods); - Assert.NotEqual(methods, new ProcTraitMethods("yoyo")); - Assert.True(methods != new ProcTraitMethods("yoyo")); - } - Assert.False(new ProcTraitMethods("yo") == null); + // Values are not referentially equal + Assert.False(methods == new ProcTraitMethods("yo")); + } } [Fact] - public void TestEqNulls() + public void TestEqNull() { ProcTraitMethods? t1 = null; ProcTraitMethods? t2 = null; @@ -116,8 +112,10 @@ public void TestEqNulls() public void TestEqContains() { var tm = new ProcTraitMethods("yo"); - var list = new List(); - list.Add(tm); + var list = new List + { + tm + }; Assert.Contains(tm, list); Assert.Contains(new ProcTraitMethods("yo"), list);