From 33bd02c2f69cdbe048cb99c459fbf620103f5099 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Tue, 24 Sep 2024 23:24:12 +0200 Subject: [PATCH] Add missing Screen.Equals/GetHashCode overrides (#17112) --- src/Avalonia.Controls/Platform/IScreenImpl.cs | 3 ++- src/Avalonia.Controls/Platform/Screen.cs | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Controls/Platform/IScreenImpl.cs b/src/Avalonia.Controls/Platform/IScreenImpl.cs index e6ac360861..5574c8170b 100644 --- a/src/Avalonia.Controls/Platform/IScreenImpl.cs +++ b/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()!); } diff --git a/src/Avalonia.Controls/Platform/Screen.cs b/src/Avalonia.Controls/Platform/Screen.cs index 8d3fe1679d..4622fee005 100644 --- a/src/Avalonia.Controls/Platform/Screen.cs +++ b/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 /// public virtual IPlatformHandle? TryGetPlatformHandle() => null; + // TODO12: make abstract + /// + public override int GetHashCode() + => RuntimeHelpers.GetHashCode(this); + + /// + public override bool Equals(object? obj) + => obj is Screen other && Equals(other); + + // TODO12: make abstract /// - 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) {