Skip to content

Commit 75888aa

Browse files
committed
Added IEquatable implementations
1 parent aea2e8a commit 75888aa

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

Runtime/SafeEvent.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace TNRD.Events
66
{
7-
public struct SafeEvent
7+
public struct SafeEvent : IEquatable<SafeEvent>
88
{
99
private HashSet<Action> subscriptions;
1010

@@ -78,5 +78,20 @@ public void Unsubscribe(Action action)
7878
safeEvent.Unsubscribe(action);
7979
return safeEvent;
8080
}
81+
82+
public bool Equals(SafeEvent other)
83+
{
84+
return Equals(subscriptions, other.subscriptions);
85+
}
86+
87+
public override bool Equals(object obj)
88+
{
89+
return obj is SafeEvent other && Equals(other);
90+
}
91+
92+
public override int GetHashCode()
93+
{
94+
return (subscriptions != null ? subscriptions.GetHashCode() : 0);
95+
}
8196
}
8297
}

Runtime/SafeEventOneParameter.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace TNRD.Events
66
{
7-
public struct SafeEvent<T>
7+
public struct SafeEvent<T> : IEquatable<SafeEvent<T>>
88
{
99
private HashSet<Action<T>> subscriptions;
1010

@@ -78,5 +78,20 @@ public void Unsubscribe(Action<T> action)
7878
safeEvent.Unsubscribe(action);
7979
return safeEvent;
8080
}
81+
82+
public bool Equals(SafeEvent<T> other)
83+
{
84+
return Equals(subscriptions, other.subscriptions);
85+
}
86+
87+
public override bool Equals(object obj)
88+
{
89+
return obj is SafeEvent<T> other && Equals(other);
90+
}
91+
92+
public override int GetHashCode()
93+
{
94+
return (subscriptions != null ? subscriptions.GetHashCode() : 0);
95+
}
8196
}
8297
}

Runtime/SafeEventTwoParameters.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace TNRD.Events
66
{
7-
public struct SafeEvent<T, T2>
7+
public struct SafeEvent<T, T2> : IEquatable<SafeEvent<T, T2>>
88
{
99
private HashSet<Action<T, T2>> subscriptions;
1010

@@ -78,5 +78,20 @@ public void Unsubscribe(Action<T, T2> action)
7878
safeEvent.Unsubscribe(action);
7979
return safeEvent;
8080
}
81+
82+
public bool Equals(SafeEvent<T, T2> other)
83+
{
84+
return Equals(subscriptions, other.subscriptions);
85+
}
86+
87+
public override bool Equals(object obj)
88+
{
89+
return obj is SafeEvent<T, T2> other && Equals(other);
90+
}
91+
92+
public override int GetHashCode()
93+
{
94+
return (subscriptions != null ? subscriptions.GetHashCode() : 0);
95+
}
8196
}
8297
}

0 commit comments

Comments
 (0)