Merge pull request #64901 from raulsntos/dotnet/equals

C#: Use pattern matching to simplify `Equals`
This commit is contained in:
Ignacio Roldán Etcheverry 2022-08-26 08:33:52 +02:00 committed by GitHub
commit e8ce36628f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 26 additions and 104 deletions

View File

@ -25,10 +25,7 @@ namespace GodotTools.IdeMessaging
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is GodotIdeMetadata metadata) return obj is GodotIdeMetadata metadata && metadata == this;
return metadata == this;
return false;
} }
public bool Equals(GodotIdeMetadata other) public bool Equals(GodotIdeMetadata other)

View File

@ -27,15 +27,13 @@ namespace GodotTools.Build
public override bool Equals(object? obj) public override bool Equals(object? obj)
{ {
if (obj is BuildInfo other) return obj is BuildInfo other &&
return other.Solution == Solution && other.Solution == Solution &&
other.Configuration == Configuration && other.RuntimeIdentifier == RuntimeIdentifier && other.Configuration == Configuration && other.RuntimeIdentifier == RuntimeIdentifier &&
other.PublishOutputDir == PublishOutputDir && other.Restore == Restore && other.PublishOutputDir == PublishOutputDir && other.Restore == Restore &&
other.Rebuild == Rebuild && other.OnlyClean == OnlyClean && other.Rebuild == Rebuild && other.OnlyClean == OnlyClean &&
other.CustomProperties == CustomProperties && other.CustomProperties == CustomProperties &&
other.LogsDirPath == LogsDirPath; other.LogsDirPath == LogsDirPath;
return false;
} }
public override int GetHashCode() public override int GetHashCode()

View File

@ -697,12 +697,7 @@ namespace Godot
/// <returns>Whether or not the AABB and the object are equal.</returns> /// <returns>Whether or not the AABB and the object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is AABB) return obj is AABB other && Equals(other);
{
return Equals((AABB)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -892,12 +892,7 @@ namespace Godot
/// <returns>Whether or not the basis matrix and the object are exactly equal.</returns> /// <returns>Whether or not the basis matrix and the object are exactly equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Basis) return obj is Basis other && Equals(other);
{
return Equals((Basis)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -1151,12 +1151,7 @@ namespace Godot
/// <returns>Whether or not the color and the other object are equal.</returns> /// <returns>Whether or not the color and the other object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Color) return obj is Color other && Equals(other);
{
return Equals((Color)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -121,8 +121,8 @@ namespace Godot
var sb = new StringBuilder(); var sb = new StringBuilder();
if (methodBase is MethodInfo) if (methodBase is MethodInfo methodInfo)
sb.AppendTypeName(((MethodInfo)methodBase).ReturnType); sb.AppendTypeName(methodInfo.ReturnType);
sb.Append(methodBase.DeclaringType?.FullName ?? "<unknown>"); sb.Append(methodBase.DeclaringType?.FullName ?? "<unknown>");
sb.Append('.'); sb.Append('.');

View File

@ -353,12 +353,7 @@ namespace Godot
/// <returns>Whether or not the plane and the other object are exactly equal.</returns> /// <returns>Whether or not the plane and the other object are exactly equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Plane) return obj is Plane other && Equals(other);
{
return Equals((Plane)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -800,11 +800,7 @@ namespace Godot
/// <returns>Whether or not the vector and the object are equal.</returns> /// <returns>Whether or not the vector and the object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Projection) return obj is Projection other && Equals(other);
{
return Equals((Projection)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -580,12 +580,7 @@ namespace Godot
/// <returns>Whether or not the quaternion and the other object are exactly equal.</returns> /// <returns>Whether or not the quaternion and the other object are exactly equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Quaternion) return obj is Quaternion other && Equals(other);
{
return Equals((Quaternion)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -426,12 +426,7 @@ namespace Godot
/// <returns>Whether or not the rect and the other object are exactly equal.</returns> /// <returns>Whether or not the rect and the other object are exactly equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Rect2) return obj is Rect2 other && Equals(other);
{
return Equals((Rect2)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -426,12 +426,7 @@ namespace Godot
/// <returns>Whether or not the rect and the other object are equal.</returns> /// <returns>Whether or not the rect and the other object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Rect2i) return obj is Rect2i other && Equals(other);
{
return Equals((Rect2i)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -602,7 +602,7 @@ namespace Godot
/// <returns>Whether or not the transform and the object are exactly equal.</returns> /// <returns>Whether or not the transform and the object are exactly equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return obj is Transform2D transform2D && Equals(transform2D); return obj is Transform2D other && Equals(other);
} }
/// <summary> /// <summary>

View File

@ -579,12 +579,7 @@ namespace Godot
/// <returns>Whether or not the transform and the object are exactly equal.</returns> /// <returns>Whether or not the transform and the object are exactly equal.</returns>
public override readonly bool Equals(object obj) public override readonly bool Equals(object obj)
{ {
if (obj is Transform3D) return obj is Transform3D other && Equals(other);
{
return Equals((Transform3D)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -925,11 +925,7 @@ namespace Godot
/// <returns>Whether or not the vector and the object are equal.</returns> /// <returns>Whether or not the vector and the object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Vector2) return obj is Vector2 other && Equals(other);
{
return Equals((Vector2)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -667,12 +667,7 @@ namespace Godot
/// <returns>Whether or not the vector and the object are equal.</returns> /// <returns>Whether or not the vector and the object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Vector2i) return obj is Vector2i other && Equals(other);
{
return Equals((Vector2i)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -993,12 +993,7 @@ namespace Godot
/// <returns>Whether or not the vector and the object are equal.</returns> /// <returns>Whether or not the vector and the object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Vector3) return obj is Vector3 other && Equals(other);
{
return Equals((Vector3)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -676,12 +676,7 @@ namespace Godot
/// <returns>Whether or not the vector and the object are equal.</returns> /// <returns>Whether or not the vector and the object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Vector3i) return obj is Vector3i other && Equals(other);
{
return Equals((Vector3i)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -754,12 +754,7 @@ namespace Godot
/// <returns>Whether or not the vector and the object are equal.</returns> /// <returns>Whether or not the vector and the object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Vector4) return obj is Vector4 other && Equals(other);
{
return Equals((Vector4)obj);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -629,12 +629,7 @@ namespace Godot
/// <returns>Whether or not the vector and the object are equal.</returns> /// <returns>Whether or not the vector and the object are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Vector4i) return obj is Vector4i other && Equals(other);
{
return Equals((Vector4i)obj);
}
return false;
} }
/// <summary> /// <summary>