diff --git a/src/AngleSharp.Css/Values/Composites/CssBackgroundLayerValue.cs b/src/AngleSharp.Css/Values/Composites/CssBackgroundLayerValue.cs index 699deb6..2b4aa78 100644 --- a/src/AngleSharp.Css/Values/Composites/CssBackgroundLayerValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssBackgroundLayerValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; sealed class CssBackgroundLayerValue : ICssCompositeValue, IEquatable { @@ -139,11 +140,17 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssBackgroundLayerValue other) { - return _clip.Equals(other._clip) && - _repeat.Equals(other._repeat) && - _attachment.Equals(other._attachment) && - _origin.Equals(other._origin) && - _size.Equals(other._size); + if(other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_clip, other._clip) && + comparer.Equals(_repeat, other._repeat) && + comparer.Equals(_attachment, other._attachment) && + comparer.Equals(_origin, other._origin) && + comparer.Equals(_size, other._size); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssBackgroundLayerValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Composites/CssBackgroundSizeValue.cs b/src/AngleSharp.Css/Values/Composites/CssBackgroundSizeValue.cs index 2a214c0..00b0a21 100644 --- a/src/AngleSharp.Css/Values/Composites/CssBackgroundSizeValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssBackgroundSizeValue.cs @@ -2,6 +2,7 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css.Dom; using System; + using System.Collections.Generic; /// /// Represents a CSS background size definition. @@ -94,7 +95,16 @@ public String CssText /// /// The other background size. /// True if both are equivalent, otherwise false. - public Boolean Equals(CssBackgroundSizeValue other) => _mode == other._mode && _height.Equals(other._height) && _width.Equals(other._width); + public Boolean Equals(CssBackgroundSizeValue other) + { + if (other is not null) + { + var comparer = EqualityComparer.Default; + return _mode == other._mode && comparer.Equals(_height, other._height) && comparer.Equals(_width, other._width); + } + + return false; + } Boolean IEquatable.Equals(ICssValue other) => other is CssBackgroundSizeValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Composites/CssBackgroundValue.cs b/src/AngleSharp.Css/Values/Composites/CssBackgroundValue.cs index 3410371..237b451 100644 --- a/src/AngleSharp.Css/Values/Composites/CssBackgroundValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssBackgroundValue.cs @@ -2,6 +2,7 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css.Dom; using System; + using System.Collections.Generic; /// /// Represents a CSS background definition. @@ -78,7 +79,13 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssBackgroundValue other) { - return _color.Equals(other._color) && _layers.Equals(other._layers); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_color, other._color) && comparer.Equals(_layers, other._layers); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssBackgroundValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Composites/CssBorderImageSliceValue.cs b/src/AngleSharp.Css/Values/Composites/CssBorderImageSliceValue.cs index ad1316a..7089e80 100644 --- a/src/AngleSharp.Css/Values/Composites/CssBorderImageSliceValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssBorderImageSliceValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents the CSS border image slice definition. @@ -124,7 +125,13 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssBorderImageSliceValue other) { - return _filled == other._filled && _bottom.Equals(other._bottom) && _left.Equals(other._left) && _right.Equals(other._right) && _top.Equals(other._top); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return _filled == other._filled && comparer.Equals(_bottom, other._bottom) && comparer.Equals(_left, other._left) && comparer.Equals(_right, other._right) && comparer.Equals(_top, other._top); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssBorderImageSliceValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Composites/CssBorderImageValue.cs b/src/AngleSharp.Css/Values/Composites/CssBorderImageValue.cs index b07f59f..2de35bb 100644 --- a/src/AngleSharp.Css/Values/Composites/CssBorderImageValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssBorderImageValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents a CSS border image definition. @@ -111,7 +112,7 @@ public String CssText #endregion - #region + #region Methods /// /// Checks if the current value is equal to the provided one. @@ -120,11 +121,17 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssBorderImageValue other) { - return _image.Equals(other._image) && - _slice.Equals(other._slice) && - _widths.Equals(other._widths) && - _outsets.Equals(other._outsets) && - _repeat.Equals(other._repeat); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_image, other._image) && + comparer.Equals(_slice, other._slice) && + comparer.Equals(_widths, other._widths) && + comparer.Equals(_outsets, other._outsets) && + comparer.Equals(_repeat, other._repeat); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssBorderImageValue value && Equals(value); @@ -137,7 +144,7 @@ ICssValue ICssValue.Compute(ICssComputeContext context) var offsets = _outsets.Compute(context); var repeat = _repeat.Compute(context); return new CssBorderImageValue(image, slice, widths, offsets, repeat); - } + } #endregion } diff --git a/src/AngleSharp.Css/Values/Composites/CssBorderRadiusValue.cs b/src/AngleSharp.Css/Values/Composites/CssBorderRadiusValue.cs index 54f2b18..c82f32d 100644 --- a/src/AngleSharp.Css/Values/Composites/CssBorderRadiusValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssBorderRadiusValue.cs @@ -2,6 +2,7 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css.Dom; using System; + using System.Collections.Generic; /// /// Represents a border radius value. @@ -74,7 +75,13 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssBorderRadiusValue other) { - return _horizontal.Equals(other._horizontal) && _vertical.Equals(other._vertical); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_horizontal, other._horizontal) && comparer.Equals(_vertical, other._vertical); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssBorderRadiusValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Composites/CssCursorValue.cs b/src/AngleSharp.Css/Values/Composites/CssCursorValue.cs index 7044b15..c46e660 100644 --- a/src/AngleSharp.Css/Values/Composites/CssCursorValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssCursorValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; using System.Linq; /// @@ -74,22 +75,26 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssCursorValue other) { - var l = _definitions.Length; - - if (_cursor.Equals(other._cursor) && l == other._definitions.Length) + if (other is not null) { - for (var i = 0; i < l; i++) - { - var a = _definitions[i]; - var b = other._definitions[i]; + var comparer = EqualityComparer.Default; + var l = _definitions.Length; - if (!a.Equals(b)) + if (comparer.Equals(_cursor, other._cursor) && l == other._definitions.Length) + { + for (var i = 0; i < l; i++) { - return false; + var a = _definitions[i]; + var b = other._definitions[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Composites/CssCustomCursorValue.cs b/src/AngleSharp.Css/Values/Composites/CssCustomCursorValue.cs index fd23ab0..cef5b3d 100644 --- a/src/AngleSharp.Css/Values/Composites/CssCustomCursorValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssCustomCursorValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; sealed class CssCustomCursorValue : ICssCompositeValue, IEquatable { @@ -72,7 +73,14 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssCustomCursorValue other) { - return _position.Equals(other._position) && _source.Equals(other._source); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_position, other._position) && + comparer.Equals(_source, other._source); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssCustomCursorValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Composites/CssFontValue.cs b/src/AngleSharp.Css/Values/Composites/CssFontValue.cs index 607ecc1..9307a4e 100644 --- a/src/AngleSharp.Css/Values/Composites/CssFontValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssFontValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents a CSS font definition. @@ -145,13 +146,19 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssFontValue other) { - return _lineHeight.Equals(other._lineHeight) && - _size.Equals(other._size) && - _weight.Equals(other._weight) && - _stretch.Equals(other._stretch) && - _variant.Equals(other._variant) && - _style.Equals(other._style) && - _fontFamilies.Equals(other._fontFamilies); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_lineHeight, other._lineHeight) && + comparer.Equals(_size, other._size) && + comparer.Equals(_weight, other._weight) && + comparer.Equals(_stretch, other._stretch) && + comparer.Equals(_variant, other._variant) && + comparer.Equals(_style, other._style) && + comparer.Equals(_fontFamilies, other._fontFamilies); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssFontValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Composites/CssGradientStopValue.cs b/src/AngleSharp.Css/Values/Composites/CssGradientStopValue.cs index a3e57a2..390205f 100644 --- a/src/AngleSharp.Css/Values/Composites/CssGradientStopValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssGradientStopValue.cs @@ -2,6 +2,7 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css.Dom; using System; + using System.Collections.Generic; /// /// More information can be found at the W3C: @@ -69,7 +70,13 @@ public CssGradientStopValue(CssColorValue color, ICssValue location = null) /// True if both are equal, otherwise false. public Boolean Equals(CssGradientStopValue other) { - return _color.Equals(other._color) && _location.Equals(other._location); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_color, other._color) && comparer.Equals(_location, other._location); + } + + return false; } ICssValue ICssValue.Compute(ICssComputeContext context) diff --git a/src/AngleSharp.Css/Values/Composites/CssGridTemplateValue.cs b/src/AngleSharp.Css/Values/Composites/CssGridTemplateValue.cs index 154011e..3c2f50f 100644 --- a/src/AngleSharp.Css/Values/Composites/CssGridTemplateValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssGridTemplateValue.cs @@ -114,7 +114,15 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssGridTemplateValue other) { - return _areas.Equals(other._areas) && _columns.Equals(other._columns) && _rows.Equals(other._rows); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_areas, other._areas) && + comparer.Equals(_columns, other._columns) && + comparer.Equals(_rows, other._rows); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssGridTemplateValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Composites/CssGridValue.cs b/src/AngleSharp.Css/Values/Composites/CssGridValue.cs index 369d919..3fda365 100644 --- a/src/AngleSharp.Css/Values/Composites/CssGridValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssGridValue.cs @@ -99,24 +99,28 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssGridValue other) { - if (_rows.Equals(other._rows) && _columns.Equals(other._columns) && _dense == other._dense) + if (other is not null) { - var l = _sizes.Length; - - if (l == other._sizes.Length) + var comparer = EqualityComparer.Default; + if (comparer.Equals(_rows, other._rows) && comparer.Equals(_columns, other._columns) && _dense == other._dense) { - for (var i = 0; i < l; i++) - { - var a = _sizes[i]; - var b = other._sizes[i]; + var l = _sizes.Length; - if (!a.Equals(b)) + if (l == other._sizes.Length) + { + for (var i = 0; i < l; i++) { - return false; + var a = _sizes[i]; + var b = other._sizes[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } } diff --git a/src/AngleSharp.Css/Values/Composites/CssImageRepeatsValue.cs b/src/AngleSharp.Css/Values/Composites/CssImageRepeatsValue.cs index ca5cfbd..44070d2 100644 --- a/src/AngleSharp.Css/Values/Composites/CssImageRepeatsValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssImageRepeatsValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents a CSS image repeat definition. @@ -81,7 +82,13 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssImageRepeatsValue other) { - return _horizontal.Equals(other._horizontal) && _vertical.Equals(other._vertical); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_horizontal, other._horizontal) && comparer.Equals(_vertical, other._vertical); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssImageRepeatsValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Composites/CssPoint2D.cs b/src/AngleSharp.Css/Values/Composites/CssPoint2D.cs index 42eb945..59decaf 100644 --- a/src/AngleSharp.Css/Values/Composites/CssPoint2D.cs +++ b/src/AngleSharp.Css/Values/Composites/CssPoint2D.cs @@ -2,6 +2,7 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css.Dom; using System; + using System.Collections.Generic; /// /// Represents a point value consisting of two distances. @@ -154,7 +155,8 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssPoint2D other) { - return _x.Equals(other._x) && _y.Equals(other._y); + var comparer = EqualityComparer.Default; + return comparer.Equals(_x, other._x) && comparer.Equals(_y, other._y); } ICssValue ICssValue.Compute(ICssComputeContext context) diff --git a/src/AngleSharp.Css/Values/Composites/CssRatioValue.cs b/src/AngleSharp.Css/Values/Composites/CssRatioValue.cs index a68e353..205aca8 100644 --- a/src/AngleSharp.Css/Values/Composites/CssRatioValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssRatioValue.cs @@ -2,6 +2,7 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css.Dom; using System; + using System.Collections.Generic; /// /// Represents a ratio (top to bottom) value. @@ -58,7 +59,8 @@ public CssRatioValue(ICssValue top, ICssValue bottom) /// True if both are equal, otherwise false. public Boolean Equals(CssRatioValue other) { - return _top.Equals(other._top) && _bottom.Equals(other._bottom); + var comparer = EqualityComparer.Default; + return comparer.Equals(_top, other._top) && comparer.Equals(_bottom, other._bottom); } ICssValue ICssValue.Compute(ICssComputeContext context) diff --git a/src/AngleSharp.Css/Values/Composites/CssShadowValue.cs b/src/AngleSharp.Css/Values/Composites/CssShadowValue.cs index 6d5d9f6..d7b27c0 100644 --- a/src/AngleSharp.Css/Values/Composites/CssShadowValue.cs +++ b/src/AngleSharp.Css/Values/Composites/CssShadowValue.cs @@ -44,7 +44,7 @@ public CssShadowValue(Boolean inset, ICssValue offsetX, ICssValue offsetY, ICssV #endregion #region Properties - + /// /// Gets the CSS text representation. /// @@ -122,12 +122,18 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssShadowValue other) { - return _blurRadius.Equals(other._blurRadius) && - _spreadRadius.Equals(other._spreadRadius) && - _color.Equals(other._color) && - _inset == other._inset && - _offsetX.Equals(other._offsetX) && - _offsetY.Equals(other._offsetY); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_blurRadius, other._blurRadius) && + comparer.Equals(_spreadRadius, other._spreadRadius) && + comparer.Equals(_color, other._color) && + _inset == other._inset && + comparer.Equals(_offsetX, other._offsetX) && + comparer.Equals(_offsetY, other._offsetY); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssShadowValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/CssChildValue.cs b/src/AngleSharp.Css/Values/CssChildValue.cs index aad3bc6..df579fa 100644 --- a/src/AngleSharp.Css/Values/CssChildValue.cs +++ b/src/AngleSharp.Css/Values/CssChildValue.cs @@ -2,6 +2,7 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css.Dom; using System; + using System.Collections.Generic; /// /// Represents a CSS value that was born from a shorthand. @@ -58,7 +59,13 @@ public CssChildValue(ICssValue parent, ICssValue value = null) /// True if both are equal, otherwise false. public Boolean Equals(CssChildValue other) { - return _parent.Equals(other._parent) && _value.Equals(other._value); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_parent, other._parent) && comparer.Equals(_value, other._value); + } + + return false; } ICssValue ICssValue.Compute(ICssComputeContext context) diff --git a/src/AngleSharp.Css/Values/Functions/CssAttrValue.cs b/src/AngleSharp.Css/Values/Functions/CssAttrValue.cs index 522d1cf..33fd2e7 100644 --- a/src/AngleSharp.Css/Values/Functions/CssAttrValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssAttrValue.cs @@ -59,10 +59,7 @@ public CssAttrValue(String attribute) /// /// The value to check against. /// True if both are equal, otherwise false. - public Boolean Equals(CssAttrValue other) - { - return _attribute.Equals(other._attribute); - } + public Boolean Equals(CssAttrValue other) => other is not null && _attribute == other._attribute; Boolean IEquatable.Equals(ICssValue other) => other is CssAttrValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssConicGradientValue.cs b/src/AngleSharp.Css/Values/Functions/CssConicGradientValue.cs index 2497ec6..80900a7 100644 --- a/src/AngleSharp.Css/Values/Functions/CssConicGradientValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssConicGradientValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; using System.Linq; /// @@ -131,22 +132,26 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssConicGradientValue other) { - var l = _stops.Length; - - if (_angle.Equals(other._angle) && _center.Equals(other._center) && _repeating == other._repeating && l == other._stops.Length) + if (other is not null) { - for (var i = 0; i < l; i++) - { - var a = _stops[i]; - var b = other._stops[i]; + var comparer = EqualityComparer.Default; + var l = _stops.Length; - if (!a.Equals(b)) + if (comparer.Equals(_angle, other._angle) && comparer.Equals(_center, other._center) && _repeating == other._repeating && l == other._stops.Length) + { + for (var i = 0; i < l; i++) { - return false; + var a = _stops[i]; + var b = other._stops[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Functions/CssContentValue.cs b/src/AngleSharp.Css/Values/Functions/CssContentValue.cs index 463e11d..6901d50 100644 --- a/src/AngleSharp.Css/Values/Functions/CssContentValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssContentValue.cs @@ -59,7 +59,15 @@ public CssContentValue(String type) /// /// The value to check against. /// True if both are equal, otherwise false. - public Boolean Equals(CssContentValue other) => _type.Equals(other._type); + public Boolean Equals(CssContentValue other) + { + if (other is not null) + { + return _type == other._type; + } + + return false; + } Boolean IEquatable.Equals(ICssValue other) => other is CssContentValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssCubicBezierValue.cs b/src/AngleSharp.Css/Values/Functions/CssCubicBezierValue.cs index 8c698af..1ba759e 100644 --- a/src/AngleSharp.Css/Values/Functions/CssCubicBezierValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssCubicBezierValue.cs @@ -4,6 +4,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents a cubic-bezier timing-function object. @@ -159,8 +160,16 @@ public String CssText /// /// The cubic bezier to compare to. /// True if both have the same parameters, otherwise false. - public Boolean Equals(CssCubicBezierValue other) => - _x1.Equals(other._x1) && _x2.Equals(other._x2) && _y1.Equals(other._y1) && _y2.Equals(other._y2); + public Boolean Equals(CssCubicBezierValue other) + { + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_x1, other._x1) && comparer.Equals(_x2, other._x2) && comparer.Equals(_y1, other._y1) && comparer.Equals(_y2, other._y2); + } + + return false; + } ICssValue ICssValue.Compute(ICssComputeContext context) { diff --git a/src/AngleSharp.Css/Values/Functions/CssFitContentValue.cs b/src/AngleSharp.Css/Values/Functions/CssFitContentValue.cs index 81b769e..b5e1d96 100644 --- a/src/AngleSharp.Css/Values/Functions/CssFitContentValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssFitContentValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents a CSS fit-content function call. @@ -59,7 +60,16 @@ public CssFitContentValue(ICssValue dim) /// /// The value to check against. /// True if both are equal, otherwise false. - public Boolean Equals(CssFitContentValue other) => _dim.Equals(other._dim); + public Boolean Equals(CssFitContentValue other) + { + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_dim, other._dim); + } + + return false; + } Boolean IEquatable.Equals(ICssValue other) => other is CssFitContentValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssFontFormatValue.cs b/src/AngleSharp.Css/Values/Functions/CssFontFormatValue.cs index d62946a..4e2c224 100644 --- a/src/AngleSharp.Css/Values/Functions/CssFontFormatValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssFontFormatValue.cs @@ -39,7 +39,7 @@ public CssFontFormatValue(String fontFormat) /// /// The value to check against. /// True if both are equal, otherwise false. - public Boolean Equals(CssFontFormatValue other) => _fontFormat.Equals(other._fontFormat); + public Boolean Equals(CssFontFormatValue other) => other is not null && _fontFormat == other._fontFormat; Boolean IEquatable.Equals(ICssValue other) => other is CssFontFormatValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssLinearGradientValue.cs b/src/AngleSharp.Css/Values/Functions/CssLinearGradientValue.cs index 6a1d470..b682266 100644 --- a/src/AngleSharp.Css/Values/Functions/CssLinearGradientValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssLinearGradientValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; using System.Linq; /// @@ -123,22 +124,26 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssLinearGradientValue other) { - var l = _stops.Length; - - if (_angle.Equals(other._angle) && _repeating == other._repeating && l == other._stops.Length) + if (other is not null) { - for (var i = 0; i < l; i++) - { - var a = _stops[i]; - var b = other._stops[i]; + var comparer = EqualityComparer.Default; + var l = _stops.Length; - if (!a.Equals(b)) + if (comparer.Equals(_angle, other._angle) && _repeating == other._repeating && l == other._stops.Length) + { + for (var i = 0; i < l; i++) { - return false; + var a = _stops[i]; + var b = other._stops[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Functions/CssLocalFontValue.cs b/src/AngleSharp.Css/Values/Functions/CssLocalFontValue.cs index 38cc33b..f6bdd1d 100644 --- a/src/AngleSharp.Css/Values/Functions/CssLocalFontValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssLocalFontValue.cs @@ -39,7 +39,7 @@ public CssLocalFontValue(String fontName) /// /// The value to check against. /// True if both are equal, otherwise false. - public Boolean Equals(CssLocalFontValue other) => _fontName.Equals(other._fontName); + public Boolean Equals(CssLocalFontValue other) => other is not null && _fontName == other._fontName; Boolean IEquatable.Equals(ICssValue other) => other is CssLocalFontValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssMatrixValue.cs b/src/AngleSharp.Css/Values/Functions/CssMatrixValue.cs index 6975cfe..ad3cfc5 100644 --- a/src/AngleSharp.Css/Values/Functions/CssMatrixValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssMatrixValue.cs @@ -4,6 +4,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; using System.Linq; /// @@ -61,22 +62,26 @@ internal CssMatrixValue(ICssValue[] values) /// True if both are equal, otherwise false. public Boolean Equals(CssMatrixValue other) { - var count = _values.Length; - - if (count == other._values.Length) + if (other is not null) { - for (var i = 0; i < count; i++) - { - var a = _values[i]; - var b = other._values[i]; + var comparer = EqualityComparer.Default; + var count = _values.Length; - if (!a.Equals(b)) + if (count == other._values.Length) + { + for (var i = 0; i < count; i++) { - return false; + var a = _values[i]; + var b = other._values[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Functions/CssMinMaxValue.cs b/src/AngleSharp.Css/Values/Functions/CssMinMaxValue.cs index 9d7f9cf..a170245 100644 --- a/src/AngleSharp.Css/Values/Functions/CssMinMaxValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssMinMaxValue.cs @@ -4,6 +4,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents a CSS minmax function call. @@ -70,7 +71,13 @@ public CssMinMaxValue(ICssValue min, ICssValue max) /// True if both are equal, otherwise false. public Boolean Equals(CssMinMaxValue other) { - return _min.Equals(other._min) && _max.Equals(other._max); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_min, other._min) && comparer.Equals(_max, other._max); + } + + return false; } ICssValue ICssValue.Compute(ICssComputeContext context) diff --git a/src/AngleSharp.Css/Values/Functions/CssPerspectiveValue.cs b/src/AngleSharp.Css/Values/Functions/CssPerspectiveValue.cs index 4b6ecf1..8df99ff 100644 --- a/src/AngleSharp.Css/Values/Functions/CssPerspectiveValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssPerspectiveValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents the distance transformation. @@ -57,7 +58,13 @@ internal CssPerspectiveValue(ICssValue distance) /// True if both are equal, otherwise false. public Boolean Equals(CssPerspectiveValue other) { - return _distance.Equals(other._distance); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_distance, other._distance); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssPerspectiveValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssRadialGradientValue.cs b/src/AngleSharp.Css/Values/Functions/CssRadialGradientValue.cs index 133ced5..81959d9 100644 --- a/src/AngleSharp.Css/Values/Functions/CssRadialGradientValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssRadialGradientValue.cs @@ -164,24 +164,28 @@ public ICssValue[] Arguments /// True if both are equal, otherwise false. public Boolean Equals(CssRadialGradientValue other) { - if (_center.Equals(other._center) && _width.Equals(other._width) && _height.Equals(other._height) && _repeating == other._repeating && _sizeMode == other._sizeMode && _circle == other._circle) + if (other is not null) { - var count = _stops.Length; - - if (count == other._stops.Length) + var comparer = EqualityComparer.Default; + if (comparer.Equals(_center, other._center) && comparer.Equals(_width, other._width) && comparer.Equals(_height, other._height) && _repeating == other._repeating && _sizeMode == other._sizeMode && _circle == other._circle) { - for (var i = 0; i < count; i++) - { - var a = _stops[i]; - var b = other._stops[i]; + var count = _stops.Length; - if (!a.Equals(b)) + if (count == other._stops.Length) + { + for (var i = 0; i < count; i++) { - return false; + var a = _stops[i]; + var b = other._stops[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } } diff --git a/src/AngleSharp.Css/Values/Functions/CssRepeatValue.cs b/src/AngleSharp.Css/Values/Functions/CssRepeatValue.cs index 07848f1..970068c 100644 --- a/src/AngleSharp.Css/Values/Functions/CssRepeatValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssRepeatValue.cs @@ -4,6 +4,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents a CSS repeat function call. @@ -70,7 +71,13 @@ public CssRepeatValue(ICssValue count, ICssValue value) /// True if both are equal, otherwise false. public Boolean Equals(CssRepeatValue other) { - return _count.Equals(other._count) && _value.Equals(other._value); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_count, other._count) && comparer.Equals(_value, other._value); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssRepeatValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssRotateValue.cs b/src/AngleSharp.Css/Values/Functions/CssRotateValue.cs index 91f77a7..ccebf27 100644 --- a/src/AngleSharp.Css/Values/Functions/CssRotateValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssRotateValue.cs @@ -4,6 +4,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents the rotate3d transformation. @@ -129,7 +130,13 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssRotateValue other) { - return _angle.Equals(other._angle) && _x.Equals(other._x) && _y.Equals(other._y) && _z.Equals(other._z); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_angle, other._angle) && comparer.Equals(_x, other._x) && comparer.Equals(_y, other._y) && comparer.Equals(_z, other._z); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssRotateValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssRunningValue.cs b/src/AngleSharp.Css/Values/Functions/CssRunningValue.cs index a2aad04..3bb8b9f 100644 --- a/src/AngleSharp.Css/Values/Functions/CssRunningValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssRunningValue.cs @@ -59,7 +59,7 @@ public CssRunningValue(String ident) /// /// The value to check against. /// True if both are equal, otherwise false. - public Boolean Equals(CssRunningValue other) => _ident.Equals(other._ident); + public Boolean Equals(CssRunningValue other) => other is not null && _ident == other._ident; Boolean IEquatable.Equals(ICssValue other) => other is CssRunningValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssScaleValue.cs b/src/AngleSharp.Css/Values/Functions/CssScaleValue.cs index e7b65a0..f9e3642 100644 --- a/src/AngleSharp.Css/Values/Functions/CssScaleValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssScaleValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents the scale3d transformation. @@ -136,7 +137,13 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssScaleValue other) { - return _sx.Equals(other._sx) && _sy.Equals(other._sy) && _sz.Equals(other._sz); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_sx, other._sx) && comparer.Equals(_sy, other._sy) && comparer.Equals(_sz, other._sz); + } + + return false; } /// diff --git a/src/AngleSharp.Css/Values/Functions/CssShapeValue.cs b/src/AngleSharp.Css/Values/Functions/CssShapeValue.cs index 760fa41..af689ed 100644 --- a/src/AngleSharp.Css/Values/Functions/CssShapeValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssShapeValue.cs @@ -4,6 +4,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents a CSS shape. @@ -93,7 +94,13 @@ public CssShapeValue(ICssValue top, ICssValue right, ICssValue bottom, ICssValue /// True if both are equal, otherwise false. public Boolean Equals(CssShapeValue other) { - return _top.Equals(other._top) && _right.Equals(other._right) && _bottom.Equals(other._bottom) && _left.Equals(other._left); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_top, other._top) && comparer.Equals(_right, other._right) && comparer.Equals(_bottom, other._bottom) && comparer.Equals(_left, other._left); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssShapeValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssSkewValue.cs b/src/AngleSharp.Css/Values/Functions/CssSkewValue.cs index 46a7b22..1a8bd59 100644 --- a/src/AngleSharp.Css/Values/Functions/CssSkewValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssSkewValue.cs @@ -3,6 +3,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents the skew transformation. @@ -107,7 +108,13 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssSkewValue other) { - return _alpha.Equals(other._alpha) && _beta.Equals(other._beta); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_alpha, other._alpha) && comparer.Equals(_beta, other._beta); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssSkewValue value && Equals(value); @@ -118,7 +125,7 @@ public Boolean Equals(CssSkewValue other) /// The transformation matrix representation. public TransformMatrix ComputeMatrix(IRenderDimensions renderDimensions) { - var a = Math.Tan((_alpha as CssAngleValue ? ?? CssAngleValue.Zero).ToRadian()); + var a = Math.Tan((_alpha as CssAngleValue? ?? CssAngleValue.Zero).ToRadian()); var b = Math.Tan((_beta as CssAngleValue? ?? CssAngleValue.Zero).ToRadian()); return new TransformMatrix(1.0, a, 0.0, b, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); } diff --git a/src/AngleSharp.Css/Values/Functions/CssStepsValue.cs b/src/AngleSharp.Css/Values/Functions/CssStepsValue.cs index b416997..205b957 100644 --- a/src/AngleSharp.Css/Values/Functions/CssStepsValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssStepsValue.cs @@ -105,7 +105,16 @@ public String CssText /// /// The value to check against. /// True if both are equal, otherwise false. - public Boolean Equals(CssStepsValue other) => _start == other._start && _intervals.Equals(other._intervals); + public Boolean Equals(CssStepsValue other) + { + if (other is not null) + { + var comparer = EqualityComparer.Default; + return _start == other._start && comparer.Equals(_intervals, other._intervals); + } + + return false; + } Boolean IEquatable.Equals(ICssValue other) => other is CssStepsValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssSymbolsValue.cs b/src/AngleSharp.Css/Values/Functions/CssSymbolsValue.cs index 7c13c7d..8f950e8 100644 --- a/src/AngleSharp.Css/Values/Functions/CssSymbolsValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssSymbolsValue.cs @@ -53,7 +53,7 @@ public CssSymbolsValue(ICssValue type, List entries) /// /// Gets the CSS text representation. /// - public String CssText =>Name.CssFunction(GetArgs()); + public String CssText => Name.CssFunction(GetArgs()); #endregion @@ -66,22 +66,26 @@ public CssSymbolsValue(ICssValue type, List entries) /// True if both are equal, otherwise false. public Boolean Equals(CssSymbolsValue other) { - var l = _entries.Count; - - if (_type.Equals(other._type) && l == other._entries.Count) + if (other is not null) { - for (var i = 0; i < l; i++) - { - var a = _entries[i]; - var b = other._entries[i]; + var comparer = EqualityComparer.Default; + var l = _entries.Count; - if (!a.Equals(b)) + if (comparer.Equals(_type, other._type) && l == other._entries.Count) + { + for (var i = 0; i < l; i++) { - return false; + var a = _entries[i]; + var b = other._entries[i]; + + if (a != b) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Functions/CssTranslateValue.cs b/src/AngleSharp.Css/Values/Functions/CssTranslateValue.cs index 47c2df5..98ac81e 100644 --- a/src/AngleSharp.Css/Values/Functions/CssTranslateValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssTranslateValue.cs @@ -4,6 +4,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Css.Dom; using AngleSharp.Text; using System; + using System.Collections.Generic; /// /// Represents the translate3d transformation. @@ -106,7 +107,13 @@ public String Name /// True if both are equal, otherwise false. public Boolean Equals(CssTranslateValue other) { - return _x.Equals(other._x) && _y.Equals(other._y) && _z.Equals(other._z); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_x, other._x) && comparer.Equals(_y, other._y) && comparer.Equals(_z, other._z); + } + + return false; } Boolean IEquatable.Equals(ICssValue other) => other is CssTranslateValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssUrlValue.cs b/src/AngleSharp.Css/Values/Functions/CssUrlValue.cs index 14a1611..5f81555 100644 --- a/src/AngleSharp.Css/Values/Functions/CssUrlValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssUrlValue.cs @@ -62,7 +62,7 @@ public CssUrlValue(String path) /// True if both are equal, otherwise false. public Boolean Equals(CssUrlValue other) { - return _path.Equals(other._path); + return other is not null && _path == other._path; } Boolean IEquatable.Equals(ICssValue other) => other is CssUrlValue value && Equals(value); diff --git a/src/AngleSharp.Css/Values/Functions/CssVarValue.cs b/src/AngleSharp.Css/Values/Functions/CssVarValue.cs index 58723c8..04d9460 100644 --- a/src/AngleSharp.Css/Values/Functions/CssVarValue.cs +++ b/src/AngleSharp.Css/Values/Functions/CssVarValue.cs @@ -103,7 +103,13 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssVarValue other) { - return _defaultValue.Equals(other._defaultValue) && _variableName.Equals(other._variableName); + if (other is not null) + { + var comparer = EqualityComparer.Default; + return comparer.Equals(_defaultValue, other._defaultValue) && _variableName == other._variableName; + } + + return false; } /// diff --git a/src/AngleSharp.Css/Values/Multiples/CssFlowRelativeValue.cs b/src/AngleSharp.Css/Values/Multiples/CssFlowRelativeValue.cs index 804b17b..c436afa 100644 --- a/src/AngleSharp.Css/Values/Multiples/CssFlowRelativeValue.cs +++ b/src/AngleSharp.Css/Values/Multiples/CssFlowRelativeValue.cs @@ -91,22 +91,26 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssFlowRelativeValue other) { - var count = _values.Length; - - if (count == other._values.Length) + if (other is not null) { - for (var i = 0; i < count; i++) - { - var a = _values[i]; - var b = other._values[i]; + var comparer = EqualityComparer.Default; + var count = _values.Length; - if (!a.Equals(b)) + if (count == other._values.Length) + { + for (var i = 0; i < count; i++) { - return false; + var a = _values[i]; + var b = other._values[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Multiples/CssListValue.cs b/src/AngleSharp.Css/Values/Multiples/CssListValue.cs index 8fcaef3..9c75eee 100644 --- a/src/AngleSharp.Css/Values/Multiples/CssListValue.cs +++ b/src/AngleSharp.Css/Values/Multiples/CssListValue.cs @@ -57,22 +57,26 @@ public CssListValue(T[] items = null) /// True if both are equal, otherwise false. public Boolean Equals(CssListValue other) { - var count = _items.Length; - - if (count == other._items.Length) + if (other is not null) { - for (var i = 0; i < count; i++) - { - var a = _items[i]; - var b = other._items[i]; + var comparer = EqualityComparer.Default; + var count = _items.Length; - if (!a.Equals(b)) + if (count == other._items.Length) + { + for (var i = 0; i < count; i++) { - return false; + var a = _items[i]; + var b = other._items[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Multiples/CssPeriodicValue.cs b/src/AngleSharp.Css/Values/Multiples/CssPeriodicValue.cs index 600aae5..6502c19 100644 --- a/src/AngleSharp.Css/Values/Multiples/CssPeriodicValue.cs +++ b/src/AngleSharp.Css/Values/Multiples/CssPeriodicValue.cs @@ -111,22 +111,26 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssPeriodicValue other) { - var count = _values.Length; - - if (count == other._values.Length) + if (other is not null) { - for (var i = 0; i < count; i++) - { - var a = _values[i]; - var b = other._values[i]; + var comparer = EqualityComparer.Default; + var count = _values.Length; - if (!a.Equals(b)) + if (count == other._values.Length) + { + for (var i = 0; i < count; i++) { - return false; + var a = _values[i]; + var b = other._values[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Multiples/CssRadiusValue.cs b/src/AngleSharp.Css/Values/Multiples/CssRadiusValue.cs index 5530bfb..1a15462 100644 --- a/src/AngleSharp.Css/Values/Multiples/CssRadiusValue.cs +++ b/src/AngleSharp.Css/Values/Multiples/CssRadiusValue.cs @@ -91,22 +91,26 @@ public String CssText /// True if both are equal, otherwise false. public Boolean Equals(CssRadiusValue other) { - var count = _values.Length; - - if (count == other._values.Length) + if (other is not null) { - for (var i = 0; i < count; i++) - { - var a = _values[i]; - var b = other._values[i]; + var comparer = EqualityComparer.Default; + var count = _values.Length; - if (!a.Equals(b)) + if (count == other._values.Length) + { + for (var i = 0; i < count; i++) { - return false; + var a = _values[i]; + var b = other._values[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Multiples/CssTupleValue.cs b/src/AngleSharp.Css/Values/Multiples/CssTupleValue.cs index c40b400..2653a3a 100644 --- a/src/AngleSharp.Css/Values/Multiples/CssTupleValue.cs +++ b/src/AngleSharp.Css/Values/Multiples/CssTupleValue.cs @@ -65,22 +65,26 @@ public CssTupleValue(T[] items = null, String separator = null) /// True if both are equal, otherwise false. public Boolean Equals(CssTupleValue other) { - var count = _items.Length; - - if (_separator.Equals(other._separator) && count == other._items.Length) + if (other is not null) { - for (var i = 0; i < count; i++) - { - var a = _items[i]; - var b = other._items[i]; + var comparer = EqualityComparer.Default; + var count = _items.Length; - if (!a.Equals(b)) + if (_separator == other._separator && count == other._items.Length) + { + for (var i = 0; i < count; i++) { - return false; + var a = _items[i]; + var b = other._items[i]; + + if (!comparer.Equals(a, b)) + { + return false; + } } - } - return true; + return true; + } } return false; diff --git a/src/AngleSharp.Css/Values/Raws/CssAnyValue.cs b/src/AngleSharp.Css/Values/Raws/CssAnyValue.cs index 7acbdb5..bf6c478 100644 --- a/src/AngleSharp.Css/Values/Raws/CssAnyValue.cs +++ b/src/AngleSharp.Css/Values/Raws/CssAnyValue.cs @@ -57,7 +57,7 @@ ICssValue ICssValue.Compute(ICssComputeContext context) return null; } - Boolean IEquatable.Equals(ICssValue other) => other is CssAnyValue o && _text.Equals(o.CssText); + Boolean IEquatable.Equals(ICssValue other) => other is CssAnyValue o && _text == o.CssText; #endregion } diff --git a/src/AngleSharp.Css/Values/Raws/CssInitialValue.cs b/src/AngleSharp.Css/Values/Raws/CssInitialValue.cs index c23e403..b01a184 100644 --- a/src/AngleSharp.Css/Values/Raws/CssInitialValue.cs +++ b/src/AngleSharp.Css/Values/Raws/CssInitialValue.cs @@ -2,6 +2,7 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css.Dom; using System; + using System.Collections.Generic; /// /// Represents the CSS initial value. @@ -45,7 +46,7 @@ public CssInitialValue(ICssValue value) ICssValue ICssValue.Compute(ICssComputeContext context) => this; - Boolean IEquatable.Equals(ICssValue other) => other is CssInitialValue o && _value.Equals(o.Value); + Boolean IEquatable.Equals(ICssValue other) => other is CssInitialValue o && EqualityComparer.Default.Equals(_value, o.Value); #endregion } diff --git a/src/AngleSharp.Css/Values/Raws/CssUnsetValue.cs b/src/AngleSharp.Css/Values/Raws/CssUnsetValue.cs index 73a1f9e..74b9af9 100644 --- a/src/AngleSharp.Css/Values/Raws/CssUnsetValue.cs +++ b/src/AngleSharp.Css/Values/Raws/CssUnsetValue.cs @@ -2,6 +2,7 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css.Dom; using System; + using System.Collections.Generic; /// /// Represents a CSS unset value. @@ -48,7 +49,7 @@ ICssValue ICssValue.Compute(ICssComputeContext context) return this; } - Boolean IEquatable.Equals(ICssValue other) => other is CssUnsetValue o && _value.Equals(o.Value); + Boolean IEquatable.Equals(ICssValue other) => other is CssUnsetValue o && EqualityComparer.Default.Equals(_value, o.Value); #endregion }