Skip to content

Commit 33bd02c

Browse files
authored
Add missing Screen.Equals/GetHashCode overrides (#17112)
1 parent aa18de5 commit 33bd02c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Avalonia.Controls/Platform/IScreenImpl.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public class PlatformScreen(IPlatformHandle platformHandle) : Screen
2727
public override IPlatformHandle? TryGetPlatformHandle() => platformHandle;
2828

2929
public override int GetHashCode() => platformHandle.GetHashCode();
30-
public override bool Equals(object? obj)
30+
31+
public override bool Equals(Screen? obj)
3132
{
3233
return obj is PlatformScreen other && platformHandle.Equals(other.TryGetPlatformHandle()!);
3334
}

src/Avalonia.Controls/Platform/Screen.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Runtime.CompilerServices;
34
using Avalonia.Diagnostics;
45
using Avalonia.Metadata;
56
using Avalonia.Utilities;
@@ -122,13 +123,19 @@ private protected Screen() { }
122123
/// </returns>
123124
public virtual IPlatformHandle? TryGetPlatformHandle() => null;
124125

126+
// TODO12: make abstract
127+
/// <inheritdoc />
128+
public override int GetHashCode()
129+
=> RuntimeHelpers.GetHashCode(this);
130+
131+
/// <inheritdoc />
132+
public override bool Equals(object? obj)
133+
=> obj is Screen other && Equals(other);
134+
135+
// TODO12: make abstract
125136
/// <inheritdoc/>
126-
public bool Equals(Screen? other)
127-
{
128-
if (other is null) return false;
129-
if (ReferenceEquals(this, other)) return true;
130-
return base.Equals(other);
131-
}
137+
public virtual bool Equals(Screen? other)
138+
=> ReferenceEquals(this, other);
132139

133140
public static bool operator ==(Screen? left, Screen? right)
134141
{

0 commit comments

Comments
 (0)