From d3ef8bfb07005a4ea74cc17d16cb652d594b034a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 6 Aug 2020 13:14:06 +0200 Subject: [PATCH] Minor (possible) bug fix --- Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs b/Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs index f8e817e0..9c27badd 100644 --- a/Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs +++ b/Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs @@ -638,9 +638,14 @@ namespace Microsoft.Toolkit.Mvvm.Messaging [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Type2 other) { + // We can't just use reference equality, as that's technically not guaranteed + // to work and might fail in very rare cases (eg. with type forwarding between + // different assemblies). Instead, we can use the == operator to compare for + // equality, which still avoids the callvirt overhead of calling Type.Equals, + // and is also implemented as a JIT intrinsic on runtimes such as .NET Core. return - ReferenceEquals(this.tMessage, other.tMessage) && - ReferenceEquals(this.tToken, other.tToken); + this.tMessage == other.tMessage && + this.tToken == other.tToken; } ///