Skip to content
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
2 changes: 1 addition & 1 deletion src/Components/Components/src/EventCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ public override int GetHashCode()
public override bool Equals(object? obj)
=> obj is EventCallback other
&& ReferenceEquals(Receiver, other.Receiver)
&& ReferenceEquals(Delegate, other.Delegate);
&& (Delegate?.Equals(other.Delegate) ?? (other.Delegate == null));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

object.Equals(a, b) performs null handling and delegates to a.Equals(b).

}
2 changes: 1 addition & 1 deletion src/Components/Components/src/EventCallbackOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ public override int GetHashCode()
public override bool Equals(object? obj)
=> obj is EventCallback<TValue> other
&& ReferenceEquals(Receiver, other.Receiver)
&& ReferenceEquals(Delegate, other.Delegate);
&& (Delegate?.Equals(other.Delegate) ?? (other.Delegate == null));
}
36 changes: 36 additions & 0 deletions src/Components/Components/test/EventCallbackTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,24 @@ await Assert.ThrowsAsync<ArgumentException>(() =>
});
}

[Fact]
public void EventCallbackOf_Equals_WhenANewDelegateIsCreated()
{
// Arrange
var component = new EventCountingComponent();

var delegate_1 = (EventArgs _) => { };
var delegate_2 = (MulticastDelegate)MulticastDelegate.CreateDelegate(typeof(Action<EventArgs>), delegate_1.Target, delegate_1.Method);
var eventcallback_1 = new EventCallback(component, delegate_1);
var eventcallback_2 = new EventCallback(component, delegate_2);

// Act
var result = eventcallback_1.Equals(eventcallback_2);

// Assert
Assert.True(result);
}

[Fact]
public async Task EventCallbackOfT_Action_Null()
{
Expand Down Expand Up @@ -415,6 +433,24 @@ public async Task EventCallbackOfT_FuncTTask_Arg()
Assert.Equal(1, component.Count);
}

[Fact]
public void EventCallbackOfT_Equals_WhenANewDelegateIsCreated()
{
// Arrange
var component = new EventCountingComponent();

var delegate_1 = (EventArgs _) => { };
var delegate_2 = (MulticastDelegate)MulticastDelegate.CreateDelegate(typeof(Action<EventArgs>), delegate_1.Target, delegate_1.Method);
var eventcallback_1 = new EventCallback<EventArgs>(component, delegate_1);
var eventcallback_2 = new EventCallback<EventArgs>(component, delegate_2);

// Act
var result = eventcallback_1.Equals(eventcallback_2);

// Assert
Assert.True(result);
}

private class EventCountingComponent : IComponent, IHandleEvent
{
public int Count;
Expand Down
Loading