Skip to content

Commit

Permalink
Add missing Screen.Equals/GetHashCode overrides (#17112)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJul authored Sep 24, 2024
1 parent aa18de5 commit 33bd02c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Avalonia.Controls/Platform/IScreenImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class PlatformScreen(IPlatformHandle platformHandle) : Screen
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()!);
}
Expand Down
19 changes: 13 additions & 6 deletions src/Avalonia.Controls/Platform/Screen.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Avalonia.Diagnostics;
using Avalonia.Metadata;
using Avalonia.Utilities;
Expand Down Expand Up @@ -122,13 +123,19 @@ private protected Screen() { }
/// </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)
{
Expand Down

0 comments on commit 33bd02c

Please sign in to comment.