Skip to content

Commit 28fdd20

Browse files
committed
Minor (possible) bug fix
1 parent 8daecad commit 28fdd20

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,14 @@ public Type2(Type tMessage, Type tToken)
638638
[MethodImpl(MethodImplOptions.AggressiveInlining)]
639639
public bool Equals(Type2 other)
640640
{
641+
// We can't just use reference equality, as that's technically not guaranteed
642+
// to work and might fail in very rare cases (eg. with type forwarding between
643+
// different assemblies). Instead, we can use the == operator to compare for
644+
// equality, which still avoids the callvirt overhead of calling Type.Equals,
645+
// and is also implemented as a JIT intrinsic on runtimes such as .NET Core.
641646
return
642-
ReferenceEquals(this.tMessage, other.tMessage) &&
643-
ReferenceEquals(this.tToken, other.tToken);
647+
this.tMessage == other.tMessage &&
648+
this.tToken == other.tToken;
644649
}
645650

646651
/// <inheritdoc/>

0 commit comments

Comments
 (0)