Browse Source

Merge pull request #3471 from MarchingCube/fix-immutable-brush-equals

Implement Equals for ImmutableSolidColorBrush.
pull/3476/head
Nikita Tsukanov 6 years ago
committed by GitHub
parent
commit
ccb4b938ec
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      src/Avalonia.Visuals/Media/Immutable/ImmutableSolidColorBrush.cs

33
src/Avalonia.Visuals/Media/Immutable/ImmutableSolidColorBrush.cs

@ -1,12 +1,14 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
namespace Avalonia.Media.Immutable
{
/// <summary>
/// Fills an area with a solid color.
/// </summary>
public readonly struct ImmutableSolidColorBrush : ISolidColorBrush
public readonly struct ImmutableSolidColorBrush : ISolidColorBrush, IEquatable<ImmutableSolidColorBrush>
{
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableSolidColorBrush"/> class.
@ -47,6 +49,35 @@ namespace Avalonia.Media.Immutable
/// </summary>
public double Opacity { get; }
public bool Equals(ImmutableSolidColorBrush other)
{
// ReSharper disable once CompareOfFloatsByEqualityOperator
return Color == other.Color && Opacity == other.Opacity;
}
public override bool Equals(object obj)
{
return obj is ImmutableSolidColorBrush other && Equals(other);
}
public override int GetHashCode()
{
unchecked
{
return (Color.GetHashCode() * 397) ^ Opacity.GetHashCode();
}
}
public static bool operator ==(ImmutableSolidColorBrush left, ImmutableSolidColorBrush right)
{
return left.Equals(right);
}
public static bool operator !=(ImmutableSolidColorBrush left, ImmutableSolidColorBrush right)
{
return !left.Equals(right);
}
/// <summary>
/// Returns a string representation of the brush.
/// </summary>

Loading…
Cancel
Save