From 05d18bdfdabce429b8a4ef826bfb5ed844233096 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sat, 16 May 2020 07:12:29 -0400 Subject: [PATCH] implement equality for Dimension2D --- MBS.Framework/Drawing/Dimension2D.cs | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/MBS.Framework/Drawing/Dimension2D.cs b/MBS.Framework/Drawing/Dimension2D.cs index 6ed22d1..7d520e1 100644 --- a/MBS.Framework/Drawing/Dimension2D.cs +++ b/MBS.Framework/Drawing/Dimension2D.cs @@ -1,6 +1,8 @@ +using System; + namespace MBS.Framework.Drawing { - public class Dimension2D : Dimension + public class Dimension2D : Dimension, IEquatable { private double mvarWidth = 0.0; public double Width { get { return mvarWidth; } set { mvarWidth = value; } } @@ -31,5 +33,36 @@ namespace MBS.Framework.Drawing { return Width.ToString() + "x" + Height.ToString(); } + + public override bool Equals(object obj) + { + if (obj is Dimension2D) + { + return ((Dimension2D)obj).Width.Equals(Width) && ((Dimension2D)obj).Height.Equals(Height); + } + return base.Equals(obj); + } + public bool Equals(Dimension2D other) + { + if ((object)other == null) return (object)this == null; + return Width.Equals(other.Width) && Height.Equals(other.Height); + } + + public static bool operator ==(Dimension2D left, Dimension2D right) + { + if ((left is null) && (right is null)) + return true; + if ((left is null) || (right is null)) + return false; + return left.Equals(right); + } + public static bool operator !=(Dimension2D left, Dimension2D right) + { + if ((left is null) && (right is null)) + return false; + if ((left is null) || (right is null)) + return true; + return !left.Equals(right); + } } }