Browse Source

Add missing Screen.Equals/GetHashCode overrides (#17112)

pull/17122/head
Julien Lebosquain 2 years ago
committed by GitHub
parent
commit
33bd02c2f6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Avalonia.Controls/Platform/IScreenImpl.cs
  2. 19
      src/Avalonia.Controls/Platform/Screen.cs

3
src/Avalonia.Controls/Platform/IScreenImpl.cs

@ -27,7 +27,8 @@ namespace Avalonia.Platform
public override IPlatformHandle? TryGetPlatformHandle() => platformHandle;
public override int GetHashCode() => platformHandle.GetHashCode();
public override bool Equals(object? obj)
public override bool Equals(Screen? obj)
{
return obj is PlatformScreen other && platformHandle.Equals(other.TryGetPlatformHandle()!);
}

19
src/Avalonia.Controls/Platform/Screen.cs

@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Avalonia.Diagnostics;
using Avalonia.Metadata;
using Avalonia.Utilities;
@ -122,13 +123,19 @@ namespace Avalonia.Platform
/// </returns>
public virtual IPlatformHandle? TryGetPlatformHandle() => null;
// TODO12: make abstract
/// <inheritdoc />
public override int GetHashCode()
=> RuntimeHelpers.GetHashCode(this);
/// <inheritdoc />
public override bool Equals(object? obj)
=> obj is Screen other && Equals(other);
// TODO12: make abstract
/// <inheritdoc/>
public bool Equals(Screen? other)
{
if (other is null) return false;
if (ReferenceEquals(this, other)) return true;
return base.Equals(other);
}
public virtual bool Equals(Screen? other)
=> ReferenceEquals(this, other);
public static bool operator ==(Screen? left, Screen? right)
{

Loading…
Cancel
Save