-
-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
14 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,19 +279,18 @@ public static async Task<Unit> Iter<T>(this Task<T> self, Action<T> f) | |
public static Task<A> PlusFirst<A>(this Task<A> ma, Task<A> mb) => | ||
default(MTaskFirst<A>).Plus(ma, mb); | ||
|
||
class PropCache<T> | ||
{ | ||
public static PropertyInfo Info = typeof(T).GetTypeInfo().DeclaredProperties.Where(p => p.Name == "Result").FirstOrDefault(); | ||
} | ||
|
||
public static async Task<A> Cast<A>(this Task source) | ||
{ | ||
if (source == null) throw new ArgumentNullException(nameof(source)); | ||
await source.ConfigureAwait(false); | ||
var prop = PropCache<A>.Info; | ||
return prop != null | ||
? (A) prop.GetValue(source) | ||
: default(A); | ||
|
||
return source.GetType() switch | ||
{ | ||
var taskTy when taskTy.IsGenericType && | ||
taskTy.GenericTypeArguments.Length == 1 && | ||
taskTy.GenericTypeArguments[0] == typeof(A) => (A)((dynamic)source).Result, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
_ => default! | ||
This comment has been minimized.
Sorry, something went wrong.
tomachristian
|
||
}; | ||
} | ||
|
||
public static async Task<Unit> ToUnit(this Task source) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@louthy it would have been more correct to check if
taskTy.GenericTypeArguments[0]
IsAssignableTotypeof(A)
.