Even better equality checking
This commit is contained in:
parent
6e960e38ff
commit
b63e8d37b5
|
@ -102,6 +102,15 @@ namespace Upsilon.BaseTypes.Number
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, obj)) return false;
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
if (ReferenceEquals(this, obj)) return true;
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (IsFloat && obj is double d)
|
||||||
|
{
|
||||||
|
return Math.Abs(((ScriptNumberDouble) this).Value - d) < 0.0000001;
|
||||||
|
}
|
||||||
|
if (!IsFloat && obj is long l)
|
||||||
|
{
|
||||||
|
return ((ScriptNumberLong) this).Value == l;
|
||||||
|
}
|
||||||
|
|
||||||
if (obj.GetType() != this.GetType()) return false;
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
return Equals((ScriptNumber) obj);
|
return Equals((ScriptNumber) obj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace Upsilon.BaseTypes
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, obj)) return false;
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
if (ReferenceEquals(this, obj)) return true;
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj is bool b) return b == Value;
|
||||||
if (obj.GetType() != this.GetType()) return false;
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
return Equals((ScriptBoolean) obj);
|
return Equals((ScriptBoolean) obj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Upsilon.BaseTypes
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, obj)) return false;
|
if (obj == null) return true;
|
||||||
if (ReferenceEquals(this, obj)) return true;
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
if (obj.GetType() != this.GetType()) return false;
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
return Equals((ScriptNull) obj);
|
return Equals((ScriptNull) obj);
|
||||||
|
|
|
@ -29,6 +29,10 @@ namespace Upsilon.BaseTypes
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
if (obj is string str)
|
||||||
|
{
|
||||||
|
return string.Equals(str, Value);
|
||||||
|
}
|
||||||
if (!(obj is ScriptString s))
|
if (!(obj is ScriptString s))
|
||||||
return false;
|
return false;
|
||||||
return Equals(s);
|
return Equals(s);
|
||||||
|
@ -39,6 +43,11 @@ namespace Upsilon.BaseTypes
|
||||||
return (Value != null ? Value.GetHashCode() : 0);
|
return (Value != null ? Value.GetHashCode() : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static implicit operator string(ScriptString s)
|
||||||
|
{
|
||||||
|
return s.Value;
|
||||||
|
}
|
||||||
|
|
||||||
private bool Equals(ScriptString s)
|
private bool Equals(ScriptString s)
|
||||||
{
|
{
|
||||||
return s != null && string.Equals(s.Value, Value);
|
return s != null && string.Equals(s.Value, Value);
|
||||||
|
|
|
@ -65,6 +65,10 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, obj)) return false;
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
if (ReferenceEquals(this, obj)) return true;
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() == Dictionary.GetType())
|
||||||
|
{
|
||||||
|
return Dictionary.Equals(obj);
|
||||||
|
}
|
||||||
if (obj.GetType() != this.GetType()) return false;
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
return Equals((DictionaryUserData) obj);
|
return Equals((DictionaryUserData) obj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,10 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, obj)) return false;
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
if (ReferenceEquals(this, obj)) return true;
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() == Value.GetType())
|
||||||
|
{
|
||||||
|
return obj.Equals(Value);
|
||||||
|
}
|
||||||
if (obj.GetType() != this.GetType()) return false;
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
return Equals((GenericUserData) obj);
|
return Equals((GenericUserData) obj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,10 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, obj)) return false;
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
if (ReferenceEquals(this, obj)) return true;
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() == List.GetType())
|
||||||
|
{
|
||||||
|
return List.Equals(obj);
|
||||||
|
}
|
||||||
if (obj.GetType() != this.GetType()) return false;
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
return Equals((ListUserData) obj);
|
return Equals((ListUserData) obj);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue