@@ -10,8 +10,7 @@ public static class TaskExtensions
1010 /// </summary>
1111 public static bool IsActive ( this Task target )
1212 {
13- if ( target is null )
14- throw new NullReferenceException ( ) ;
13+ if ( target is null ) throw new ArgumentNullException ( nameof ( target ) ) ;
1514
1615 switch ( target . Status )
1716 {
@@ -38,8 +37,7 @@ public static bool IsActive(this Task target)
3837 /// <returns>True if start attempt was successful.</returns>
3938 public static bool EnsureStarted ( this Task target , TaskScheduler ? scheduler = default )
4039 {
41- if ( target is null ) throw new NullReferenceException ( ) ;
42-
40+ if ( target is null ) throw new ArgumentNullException ( nameof ( target ) ) ;
4341 if ( target . Status != TaskStatus . Created ) return false ;
4442 try
4543 {
@@ -70,6 +68,7 @@ public static bool EnsureStarted(this Task target, TaskScheduler? scheduler = de
7068 public static TTask OnFullfilled < TTask > ( this TTask target , Action action )
7169 where TTask : Task
7270 {
71+ if ( target is null ) throw new ArgumentNullException ( nameof ( target ) ) ;
7372 target . ContinueWith ( task =>
7473 {
7574 if ( task . Status == TaskStatus . RanToCompletion ) action ( ) ;
@@ -87,6 +86,7 @@ public static TTask OnFullfilled<TTask>(this TTask target, Action action)
8786 /// <returns>The target object. Allows for method chaining.</returns>
8887 public static Task < T > OnFullfilled < T > ( this Task < T > target , Action < T > action )
8988 {
89+ if ( target is null ) throw new ArgumentNullException ( nameof ( target ) ) ;
9090 target . ContinueWith ( task =>
9191 {
9292 if ( task . Status == TaskStatus . RanToCompletion ) action ( task . Result ) ;
@@ -106,6 +106,7 @@ public static Task<T> OnFullfilled<T>(this Task<T> target, Action<T> action)
106106 public static TTask OnFullfilled < TTask , T > ( this TTask target , Func < T > action )
107107 where TTask : Task
108108 {
109+ if ( target is null ) throw new ArgumentNullException ( nameof ( target ) ) ;
109110 target . ContinueWith ( task =>
110111 {
111112 if ( task . Status == TaskStatus . RanToCompletion ) action ( ) ;
@@ -124,6 +125,7 @@ public static TTask OnFullfilled<TTask, T>(this TTask target, Func<T> action)
124125 public static TTask OnFaulted < TTask > ( this TTask target , Action < Exception > action )
125126 where TTask : Task
126127 {
128+ if ( target is null ) throw new ArgumentNullException ( nameof ( target ) ) ;
127129 target . ContinueWith ( task =>
128130 {
129131 if ( task . IsFaulted ) action ( task . Exception ) ;
@@ -143,6 +145,7 @@ public static TTask OnFaulted<TTask>(this TTask target, Action<Exception> action
143145 public static TTask OnCancelled < TTask > ( this TTask target , Action action )
144146 where TTask : Task
145147 {
148+ if ( target is null ) throw new ArgumentNullException ( nameof ( target ) ) ;
146149 target . ContinueWith ( task =>
147150 {
148151 if ( ! task . IsCanceled ) action ( ) ;
@@ -162,6 +165,7 @@ public static TTask OnCancelled<TTask>(this TTask target, Action action)
162165 public static TTask OnCancelled < TTask , T > ( this TTask target , Func < T > action )
163166 where TTask : Task
164167 {
168+ if ( target is null ) throw new ArgumentNullException ( nameof ( target ) ) ;
165169 target . ContinueWith ( task =>
166170 {
167171 if ( ! task . IsCanceled ) action ( ) ;
0 commit comments