diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs index a5f4a0e867..8e0d836b1a 100644 --- a/src/bindings/mono/eina_mono/eina_value.cs +++ b/src/bindings/mono/eina_mono/eina_value.cs @@ -2918,7 +2918,7 @@ public class Value : IDisposable, IComparable, IEquatable return eina_value_convert(this.Handle, destination.Handle); } - /// Compare two eina values. + /// Compare two . /// Since EFL 1.23. /// /// The object to be compared to. @@ -2926,7 +2926,7 @@ public class Value : IDisposable, IComparable, IEquatable /// the other. public int CompareTo(Value other) { - if (other == null) + if (object.ReferenceEquals(other, null)) { return 1; } @@ -2936,15 +2936,21 @@ public class Value : IDisposable, IComparable, IEquatable return eina_value_compare_wrapper(this.Handle, other.Handle); } - /// Compare to other values. + /// Compare two values. /// Since EFL 1.23. /// - /// The object to be compared to. - /// -1, 0 or 1 if this value is respectively smaller than, equal to or greater than - /// the other. - public int Compare(Value other) + /// The left value. + /// The right value. + /// -1, 0 or 1 if lhs is respectively + /// smaller than, equal to or greater than the rhs. + public static int Compare(Value lhs, Value rhs) { - return this.CompareTo(other); + if (object.ReferenceEquals(lhs, rhs)) + return 0; + if (object.ReferenceEquals(lhs, null)) + return -1; + + return lhs.CompareTo(rhs); } /// Returns whether this value is equal to the given object. @@ -2959,13 +2965,7 @@ public class Value : IDisposable, IComparable, IEquatable return false; } - Value v = obj as Value; - if (v == null) - { - return false; - } - - return this.Equals(v); + return this.Equals(obj as Value); } /// Returns whether this value is equal to the given value. @@ -2973,17 +2973,7 @@ public class Value : IDisposable, IComparable, IEquatable /// /// The value to be compared to. /// true if this value is equal to other. - public bool Equals(Value other) - { - try - { - return this.CompareTo(other) == 0; - } - catch (ObjectDisposedException) - { - return false; - } - } + public bool Equals(Value other) => this.CompareTo(other) == 0; /// Gets the hash code for this value. /// @@ -2995,70 +2985,72 @@ public class Value : IDisposable, IComparable, IEquatable return this.Handle.ToInt32(); } - /// Returns whether both values are null or x is equal to y. + /// Returns whether both values are null or lhs is equal to rhs. /// /// Since EFL 1.23. /// - /// true if both parameters are null or if x is equal - /// to y. - public static bool operator==(Value x, Value y) + /// The left hand side of the operator. + /// The right hand side of the operator. + /// true if both parameters are null or if lhs is equal + /// to lhs. + public static bool operator==(Value lhs, Value rhs) { - if (object.ReferenceEquals(x, null)) - { - return object.ReferenceEquals(y, null); - } + if (object.ReferenceEquals(lhs, null)) + return object.ReferenceEquals(rhs, null); - return x.Equals(y); + return lhs.Equals(rhs); } - /// Returns whether x is different from y. + /// Returns whether lhs is different from rhs. /// /// Since EFL 1.23. /// - /// true if x is different from y. - public static bool operator!=(Value x, Value y) - { - if (object.ReferenceEquals(x, null)) - { - return !object.ReferenceEquals(y, null); - } + /// The left hand side of the operator. + /// The right hand side of the operator. + /// true if lhs is different from rhs. + public static bool operator!=(Value lhs, Value rhs) => !(lhs == rhs); - return !x.Equals(y); - } - - /// Returns whether x is greater than y. + /// Returns whether lhs is less than rhs. /// /// If either parameter is null, false is returned. /// /// Since EFL 1.23. /// - /// true if x is greater than y. - public static bool operator>(Value x, Value y) - { - if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null)) - { - return false; - } + /// The left hand side of the operator. + /// The right hand side of the operator. + /// true if lhs is less than rhs. + public static bool operator<(Value lhs, Value rhs) => (Compare(lhs, rhs) < 0); - return x.CompareTo(y) > 0; - } - - /// Returns whether x is smaller than y. + /// Returns whether lhs is greater than rhs. /// /// If either parameter is null, false is returned. /// /// Since EFL 1.23. /// - /// true if x is smaller than y. - public static bool operator<(Value x, Value y) - { - if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null)) - { - return false; - } + /// The left hand side of the operator. + /// The right hand side of the operator. + /// true if lhs is greater than rhs. + public static bool operator>(Value lhs, Value rhs) => rhs < lhs; - return x.CompareTo(y) < 0; - } + /// + /// Returns whether lhs is equal or less than rhs. + /// Since EFL 1.23. + /// + /// The left hand side of the operator. + /// The right hand side of the operator. + /// true if lhs is equal + /// or less than rhs. + public static bool operator<=(Value lhs, Value rhs) => !(lhs > rhs); + + /// + /// Returns whether lhs is equal or greater than rhs. + /// Since EFL 1.23. + /// + /// The left hand side of the operator. + /// The right hand side of the operator. + /// true if lhs is equal + /// or greater than rhs. + public static bool operator>=(Value lhs, Value rhs) => !(lhs < rhs); /// Converts value to string. diff --git a/src/tests/efl_mono/Value.cs b/src/tests/efl_mono/Value.cs index 969b336e5f..6bf36d708b 100644 --- a/src/tests/efl_mono/Value.cs +++ b/src/tests/efl_mono/Value.cs @@ -459,7 +459,7 @@ public static class TestEinaValue { } } - public static void TestValueComparisonOverloadLessMore() + public static void TestValueComparisonOverloadLessGreater() { using (Eina.Value a = new Eina.Value(Eina.ValueType.Int32)) using (Eina.Value b = new Eina.Value(Eina.ValueType.Int32)) { @@ -467,9 +467,18 @@ public static class TestEinaValue { Test.Assert(b.Set(0)); Test.Assert(a > b); + Test.Assert(!(a <= b)); Test.Assert(!(a < b)); + Test.Assert(a >= b); Test.Assert(b < a); + Test.Assert(!(b >= a)); Test.Assert(!(b > a)); + Test.Assert(b <= a); + + Test.AssertEquals(a > b, !(a <= b)); + Test.AssertEquals(!(a < b), a >= b); + Test.AssertEquals(b < a, !(b >= a)); + Test.AssertEquals(!(b > a), b <= a); } }