Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 383241b

Browse files
committedAug 5, 2024
Added null propagation check
1 parent 2feb4ba commit 383241b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
 

‎Runtime/Condition.Extensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ public static class ConditionExtensions {
2626

2727
/// <summary> If the condition is true, execute the action </summary>
2828
public static void IfTrue(this bool condition, Action action) {
29-
if (condition) action();
29+
if (condition) action?.Invoke();
3030
}
3131
/// <summary> If the condition is true, execute the action </summary>
3232
public static void IfTrue<T>(this bool condition, Func<object> action){
33-
if (condition) action();
33+
if (condition) action?.Invoke();
3434
}
3535

3636
/// <summary> If the condition is false, execute the action </summary>
3737
public static void IfFalse(this bool condition, Action action) {
38-
if (!condition) action();
38+
if (!condition) action?.Invoke();
3939
}
4040

4141
/// <summary> Select the action to perform based on the condition </summary>
4242
public static void Select(this bool condition, Action onTrue, Action onFalse) {
43-
if (condition) onTrue();
43+
if (condition) onTrue?.Invoke();
4444
else onFalse();
4545
}
4646

4747
/// <summary> Select the action to perform based on the condition </summary>
4848
public static void Select<T>(this bool condition, Action<T> onTrue, Action<T> onFalse, T arg) {
49-
if (condition) onTrue(arg);
49+
if (condition) onTrue?.Invoke(arg);
5050
else onFalse(arg);
5151
}
5252

@@ -58,11 +58,11 @@ public static void Select<T>(this bool condition, Action<T> onTrue, Action<T> on
5858

5959
/// <summary> Perform an action with passed arguments if true</summary>
6060
public static void IfTrue<T>(this bool condition, Action<T> action, T arg) {
61-
if (condition) action(arg);
61+
if (condition) action?.Invoke(arg);
6262
}
6363
/// <summary> Perform an action with passed arguments if false</summary>
6464
public static void IfFalse<T>(this bool condition, Action<T> action, T arg) {
65-
if (!condition) action(arg);
65+
if (!condition) action?.Invoke(arg);
6666
}
6767

6868
public static void flip(this ref bool condition) => condition = !condition;

0 commit comments

Comments
 (0)
Please sign in to comment.