From a3a219d6aac2bbeb66a6e4de92f3a7bd302e1736 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Mon, 28 Dec 2015 15:18:18 +0000 Subject: [PATCH] Implement IEquatable Implementation of the IEquatable to avoid boxing as suggested by the .NET guidelines (8.6) --- Splat/Points/Point.cs | 16 +++++++++++++++- Splat/Points/PointF.cs | 16 +++++++++++++++- Splat/Points/Rectangle.cs | 17 ++++++++++++++++- Splat/Points/RectangleF.cs | 17 ++++++++++++++++- Splat/Points/Size.cs | 17 ++++++++++++++++- Splat/Points/SizeF.cs | 17 ++++++++++++++++- 6 files changed, 94 insertions(+), 6 deletions(-) diff --git a/Splat/Points/Point.cs b/Splat/Points/Point.cs index 42a68a855..44e609dbc 100644 --- a/Splat/Points/Point.cs +++ b/Splat/Points/Point.cs @@ -39,6 +39,7 @@ namespace System.Drawing { public struct Point + : IEquatable { // Private x and y coordinate fields. private int x, y; @@ -317,6 +318,19 @@ public int Y } } + /// + /// Equals Method + /// + /// + /// + /// Checks equivalence of this Point and another Point. + /// + + public bool Equals(Point other) + { + return ((this.X == other.X) && (this.Y == other.Y)); + } + /// /// Equals Method /// @@ -330,7 +344,7 @@ public override bool Equals(object obj) if (!(obj is Point)) return false; - return (this == (Point)obj); + return this.Equals((Point)obj); } /// diff --git a/Splat/Points/PointF.cs b/Splat/Points/PointF.cs index b9f533f2a..71d04de9d 100644 --- a/Splat/Points/PointF.cs +++ b/Splat/Points/PointF.cs @@ -35,6 +35,7 @@ namespace System.Drawing { public struct PointF + : IEquatable { // Private x and y coordinate fields. private float x, y; @@ -201,6 +202,19 @@ public float Y } } + /// + /// Equals Method + /// + /// + /// + /// Checks equivalence of this PointF and another PointF. + /// + + public bool Equals(PointF other) + { + return ((this.X == other.X) && (this.Y == other.Y)); + } + /// /// Equals Method /// @@ -214,7 +228,7 @@ public override bool Equals(object obj) if (!(obj is PointF)) return false; - return (this == (PointF)obj); + return this.Equals((PointF)obj); } /// diff --git a/Splat/Points/Rectangle.cs b/Splat/Points/Rectangle.cs index 8831fa965..e88864461 100644 --- a/Splat/Points/Rectangle.cs +++ b/Splat/Points/Rectangle.cs @@ -38,6 +38,7 @@ namespace System.Drawing { public struct Rectangle + : IEquatable { private int x, y, width, height; @@ -564,6 +565,20 @@ public bool Contains(Rectangle rect) return (rect == Intersect(this, rect)); } + /// + /// Equals Method + /// + /// + /// + /// Checks equivalence of this Rectangle and another Rectangle. + /// + + public bool Equals(Rectangle other) + { + return ((this.Location == other.Location) && + (this.Size == other.Size)); + } + /// /// Equals Method /// @@ -577,7 +592,7 @@ public override bool Equals(object obj) if (!(obj is Rectangle)) return false; - return (this == (Rectangle)obj); + return this.Equals((Rectangle)obj); } /// diff --git a/Splat/Points/RectangleF.cs b/Splat/Points/RectangleF.cs index d17b33477..40c5caec5 100644 --- a/Splat/Points/RectangleF.cs +++ b/Splat/Points/RectangleF.cs @@ -33,6 +33,7 @@ namespace System.Drawing { public struct RectangleF + : IEquatable { private float x, y, width, height; @@ -510,6 +511,20 @@ public bool Contains(RectangleF rect) return (rect == Intersect(this, rect)); } + /// + /// Equals Method + /// + /// + /// + /// Checks equivalence of this RectangleF and an RectangleF. + /// + + public bool Equals(RectangleF other) + { + return ((this.Location == other.Location) && + (this.Size == other.Size)); + } + /// /// Equals Method /// @@ -523,7 +538,7 @@ public override bool Equals(object obj) if (!(obj is RectangleF)) return false; - return (this == (RectangleF)obj); + return this.Equals((RectangleF)obj); } /// diff --git a/Splat/Points/Size.cs b/Splat/Points/Size.cs index f9a1c7e85..c2505d15b 100644 --- a/Splat/Points/Size.cs +++ b/Splat/Points/Size.cs @@ -39,6 +39,7 @@ namespace System.Drawing { public struct Size + : IEquatable { // Private Height and width fields. @@ -302,6 +303,20 @@ public int Height } } + /// + /// Equals Method + /// + /// + /// + /// Checks equivalence of this Size and another Size. + /// + + public bool Equals(Size other) + { + return ((this.Width == other.Width) && + (this.Height == other.Height)); + } + /// /// Equals Method /// @@ -315,7 +330,7 @@ public override bool Equals(object obj) if (!(obj is Size)) return false; - return (this == (Size)obj); + return this.Equals((Size)obj); } /// diff --git a/Splat/Points/SizeF.cs b/Splat/Points/SizeF.cs index 11343dc84..73ec3afd5 100644 --- a/Splat/Points/SizeF.cs +++ b/Splat/Points/SizeF.cs @@ -39,6 +39,7 @@ namespace System.Drawing { public struct SizeF + : IEquatable { // Private height and width fields. private float width, height; @@ -238,6 +239,20 @@ public float Height } } + /// + /// Equals Method + /// + /// + /// + /// Checks equivalence of this SizeF and another SizeF. + /// + + public bool Equals(SizeF other) + { + return ((this.Width == other.Width) && + (this.Height == other.Height)); + } + /// /// Equals Method /// @@ -251,7 +266,7 @@ public override bool Equals(object obj) if (!(obj is SizeF)) return false; - return (this == (SizeF)obj); + return this.Equals((SizeF)obj); } ///