Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing Screen.Equals/GetHashCode overrides #17112

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading