forked from enlightenment/efl
csharp: Add comparables operators to eina_value.
Summary: ref T8394 Reviewers: lauromoura, felipealmeida, segfaultxavi, YOhoho, bu5hm4n Reviewed By: YOhoho Subscribers: bu5hm4n, cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8394 Differential Revision: https://phab.enlightenment.org/D10458
This commit is contained in:
parent
91ae0ea12f
commit
19588be0b9
|
@ -2918,7 +2918,7 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
|
||||||
return eina_value_convert(this.Handle, destination.Handle);
|
return eina_value_convert(this.Handle, destination.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Compare two eina values.
|
/// <summary>Compare two <see cref="Eina.Value" />.
|
||||||
/// <para>Since EFL 1.23.</para>
|
/// <para>Since EFL 1.23.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="other">The object to be compared to.</param>
|
/// <param name="other">The object to be compared to.</param>
|
||||||
|
@ -2926,7 +2926,7 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
|
||||||
/// the <c>other</c>.</returns>
|
/// the <c>other</c>.</returns>
|
||||||
public int CompareTo(Value other)
|
public int CompareTo(Value other)
|
||||||
{
|
{
|
||||||
if (other == null)
|
if (object.ReferenceEquals(other, null))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -2936,15 +2936,21 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
|
||||||
return eina_value_compare_wrapper(this.Handle, other.Handle);
|
return eina_value_compare_wrapper(this.Handle, other.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Compare to other values.
|
/// <summary>Compare two values.
|
||||||
/// <para>Since EFL 1.23.</para>
|
/// <para>Since EFL 1.23.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="other">The object to be compared to.</param>
|
/// <param name="lhs">The left value.</param>
|
||||||
/// <returns><c>-1</c>, <c>0</c> or <c>1</c> if this value is respectively smaller than, equal to or greater than
|
/// <param name="rhs">The right value.</param>
|
||||||
/// the <c>other</c>.</returns>
|
/// <returns><c>-1</c>, <c>0</c> or <c>1</c> if <c>lhs</c> is respectively
|
||||||
public int Compare(Value other)
|
/// smaller than, equal to or greater than the <c>rhs</c>.</returns>
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Returns whether this value is equal to the given object.
|
/// <summary>Returns whether this value is equal to the given object.
|
||||||
|
@ -2959,13 +2965,7 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value v = obj as Value;
|
return this.Equals(obj as Value);
|
||||||
if (v == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.Equals(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Returns whether this value is equal to the given value.
|
/// <summary>Returns whether this value is equal to the given value.
|
||||||
|
@ -2973,17 +2973,7 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="other">The value to be compared to.</param>
|
/// <param name="other">The value to be compared to.</param>
|
||||||
/// <returns><c>true</c> if this value is equal to <c>other</c>.</returns>
|
/// <returns><c>true</c> if this value is equal to <c>other</c>.</returns>
|
||||||
public bool Equals(Value other)
|
public bool Equals(Value other) => this.CompareTo(other) == 0;
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return this.CompareTo(other) == 0;
|
|
||||||
}
|
|
||||||
catch (ObjectDisposedException)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Gets the hash code for this value.
|
/// <summary>Gets the hash code for this value.
|
||||||
///
|
///
|
||||||
|
@ -2995,70 +2985,72 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
|
||||||
return this.Handle.ToInt32();
|
return this.Handle.ToInt32();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Returns whether both values are null or <c>x</c> is equal to <c>y</c>.
|
/// <summary>Returns whether both values are null or <c>lhs</c> is equal to <c>rhs</c>.
|
||||||
///
|
///
|
||||||
/// <para>Since EFL 1.23.</para>
|
/// <para>Since EFL 1.23.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns><c>true</c> if both parameters are <c>null</c> or if <c>x</c> is equal
|
/// <param name="lhs">The left hand side of the operator.</param>
|
||||||
/// to <c>y</c>.</returns>
|
/// <param name="rhs">The right hand side of the operator.</param>
|
||||||
public static bool operator==(Value x, Value y)
|
/// <returns><c>true</c> if both parameters are <c>null</c> or if <c>lhs</c> is equal
|
||||||
|
/// to <c>lhs</c>.</returns>
|
||||||
|
public static bool operator==(Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
if (object.ReferenceEquals(x, null))
|
if (object.ReferenceEquals(lhs, null))
|
||||||
{
|
return object.ReferenceEquals(rhs, null);
|
||||||
return object.ReferenceEquals(y, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return x.Equals(y);
|
return lhs.Equals(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Returns whether <c>x</c> is different from <c>y</c>.
|
/// <summary>Returns whether <c>lhs</c> is different from <c>rhs</c>.
|
||||||
///
|
///
|
||||||
/// <para>Since EFL 1.23.</para>
|
/// <para>Since EFL 1.23.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns><c>true</c> if <c>x</c> is different from <c>y</c>.</returns>
|
/// <param name="lhs">The left hand side of the operator.</param>
|
||||||
public static bool operator!=(Value x, Value y)
|
/// <param name="rhs">The right hand side of the operator.</param>
|
||||||
{
|
/// <returns><c>true</c> if <c>lhs</c> is different from <c>rhs</c>.</returns>
|
||||||
if (object.ReferenceEquals(x, null))
|
public static bool operator!=(Value lhs, Value rhs) => !(lhs == rhs);
|
||||||
{
|
|
||||||
return !object.ReferenceEquals(y, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return !x.Equals(y);
|
/// <summary>Returns whether <c>lhs</c> is less than <c>rhs</c>.
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Returns whether <c>x</c> is greater than <c>y</c>.
|
|
||||||
///
|
///
|
||||||
/// <para>If either parameter is <c>null</c>, <c>false</c> is returned.</para>
|
/// <para>If either parameter is <c>null</c>, <c>false</c> is returned.</para>
|
||||||
///
|
///
|
||||||
/// <para>Since EFL 1.23.</para>
|
/// <para>Since EFL 1.23.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns><c>true</c> if <c>x</c> is greater than <c>y</c>.</returns>
|
/// <param name="lhs">The left hand side of the operator.</param>
|
||||||
public static bool operator>(Value x, Value y)
|
/// <param name="rhs">The right hand side of the operator.</param>
|
||||||
{
|
/// <returns><c>true</c> if <c>lhs</c> is less than <c>rhs</c>.</returns>
|
||||||
if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null))
|
public static bool operator<(Value lhs, Value rhs) => (Compare(lhs, rhs) < 0);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return x.CompareTo(y) > 0;
|
/// <summary>Returns whether <c>lhs</c> is greater than <c>rhs</c>.
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Returns whether <c>x</c> is smaller than <c>y</c>.
|
|
||||||
///
|
///
|
||||||
/// <para>If either parameter is <c>null</c>, <c>false</c> is returned.</para>
|
/// <para>If either parameter is <c>null</c>, <c>false</c> is returned.</para>
|
||||||
///
|
///
|
||||||
/// <para>Since EFL 1.23.</para>
|
/// <para>Since EFL 1.23.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns><c>true</c> if <c>x</c> is smaller than <c>y</c>.</returns>
|
/// <param name="lhs">The left hand side of the operator.</param>
|
||||||
public static bool operator<(Value x, Value y)
|
/// <param name="rhs">The right hand side of the operator.</param>
|
||||||
{
|
/// <returns><c>true</c> if <c>lhs</c> is greater than <c>rhs</c>.</returns>
|
||||||
if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null))
|
public static bool operator>(Value lhs, Value rhs) => rhs < lhs;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return x.CompareTo(y) < 0;
|
/// <summary>
|
||||||
}
|
/// Returns whether <c>lhs</c> is equal or less than <c>rhs</c>.
|
||||||
|
/// <para>Since EFL 1.23.</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="lhs">The left hand side of the operator.</param>
|
||||||
|
/// <param name="rhs">The right hand side of the operator.</param>
|
||||||
|
/// <returns><c>true</c> if <c>lhs</c> is equal
|
||||||
|
/// or less than <c>rhs</c>.</returns>
|
||||||
|
public static bool operator<=(Value lhs, Value rhs) => !(lhs > rhs);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns whether <c>lhs</c> is equal or greater than <c>rhs</c>.
|
||||||
|
/// <para>Since EFL 1.23.</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="lhs">The left hand side of the operator.</param>
|
||||||
|
/// <param name="rhs">The right hand side of the operator.</param>
|
||||||
|
/// <returns><c>true</c> if <c>lhs</c> is equal
|
||||||
|
/// or greater than <c>rhs</c>.</returns>
|
||||||
|
public static bool operator>=(Value lhs, Value rhs) => !(lhs < rhs);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Converts value to string.
|
/// <summary>Converts value to string.
|
||||||
|
|
|
@ -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 a = new Eina.Value(Eina.ValueType.Int32))
|
||||||
using (Eina.Value b = 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(b.Set(0));
|
||||||
|
|
||||||
Test.Assert(a > b);
|
Test.Assert(a > b);
|
||||||
|
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.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue