Skip to content

Commit 69979b9

Browse files
authored
Merge pull request #6 from Thundernerd/develop
Fixed incorrectly throwing error when a method is static
2 parents 30e238c + 3f9e04e commit 69979b9

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [1.2.1] - 2020-10-15
4+
5+
### Fixed
6+
- Incorrectly trowing SubscriptionIsNullException when a method is static
7+
38
## [1.2.0] - 2020-09-02
49

510
### Updated

Runtime/SafeEvent.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public void Invoke()
3333

3434
private static void ThrowIfInvalidSubscription(Action subscription)
3535
{
36-
if (subscription?.Target == null)
36+
if (subscription == null)
3737
{
3838
throw new SubscriptionIsNullException();
3939
}
4040

41-
if (subscription.Target is Component component && !component)
41+
switch (subscription.Target)
4242
{
43-
throw new SubscriptionIsNullException();
44-
}
45-
46-
if (subscription.Target is GameObject gameObject && !gameObject)
47-
{
48-
throw new SubscriptionIsNullException();
43+
case null when !subscription.Method.IsStatic:
44+
throw new SubscriptionIsNullException();
45+
case Component component when !component:
46+
throw new SubscriptionIsNullException();
47+
case GameObject gameObject when !gameObject:
48+
throw new SubscriptionIsNullException();
4949
}
5050
}
5151

Runtime/SafeEventOneParameter.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public void Invoke(T obj)
3333

3434
private static void ThrowIfInvalidSubscription(Action<T> subscription)
3535
{
36-
if (subscription?.Target == null)
36+
if (subscription == null)
3737
{
3838
throw new SubscriptionIsNullException();
3939
}
4040

41-
if (subscription.Target is Component component && !component)
41+
switch (subscription.Target)
4242
{
43-
throw new SubscriptionIsNullException();
44-
}
45-
46-
if (subscription.Target is GameObject gameObject && !gameObject)
47-
{
48-
throw new SubscriptionIsNullException();
43+
case null when !subscription.Method.IsStatic:
44+
throw new SubscriptionIsNullException();
45+
case Component component when !component:
46+
throw new SubscriptionIsNullException();
47+
case GameObject gameObject when !gameObject:
48+
throw new SubscriptionIsNullException();
4949
}
5050
}
5151

Runtime/SafeEventTwoParameters.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public void Invoke(T arg1, T2 arg2)
3333

3434
private static void ThrowIfInvalidSubscription(Action<T, T2> subscription)
3535
{
36-
if (subscription?.Target == null)
36+
if (subscription == null)
3737
{
3838
throw new SubscriptionIsNullException();
3939
}
4040

41-
if (subscription.Target is Component component && !component)
41+
switch (subscription.Target)
4242
{
43-
throw new SubscriptionIsNullException();
44-
}
45-
46-
if (subscription.Target is GameObject gameObject && !gameObject)
47-
{
48-
throw new SubscriptionIsNullException();
43+
case null when !subscription.Method.IsStatic:
44+
throw new SubscriptionIsNullException();
45+
case Component component when !component:
46+
throw new SubscriptionIsNullException();
47+
case GameObject gameObject when !gameObject:
48+
throw new SubscriptionIsNullException();
4949
}
5050
}
5151

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "net.tnrd.safeevent",
33
"displayName": "Safe Event",
4-
"version": "1.2.0",
4+
"version": "1.2.1",
55
"unity": "2019.1",
66
"description": "An event class that has extra checks to help prevent mistakes",
77
"keywords": [

0 commit comments

Comments
 (0)