From 369e30587180cceccd38ce7b4ed395f70c6a4dab Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Fri, 25 Oct 2019 10:08:19 -0400 Subject: [PATCH] Add equality comparison support for most common Dims (#278) Specifically factor, fill and absolute now support making comparisons. --- Terminal.Gui/Types/PosDim.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Types/PosDim.cs b/Terminal.Gui/Types/PosDim.cs index 7423c09c6..bf7fdf16c 100644 --- a/Terminal.Gui/Types/PosDim.cs +++ b/Terminal.Gui/Types/PosDim.cs @@ -311,6 +311,11 @@ namespace Terminal.Gui { { return $"Dim.Factor({factor})"; } + + public override int GetHashCode () => factor.GetHashCode(); + + public override bool Equals (object other) => other is DimFactor f && f.factor == factor; + } /// @@ -339,6 +344,11 @@ namespace Terminal.Gui { { return n; } + + public override int GetHashCode () => n.GetHashCode(); + + public override bool Equals (object other) => other is DimAbsolute abs && abs.n == n; + } class DimFill : Dim { @@ -353,7 +363,11 @@ namespace Terminal.Gui { internal override int Anchor (int width) { return width-margin; - } + } + + public override int GetHashCode () => margin.GetHashCode(); + + public override bool Equals (object other) => other is DimFill fill && fill.margin == margin; } static DimFill zeroMargin;