Created
October 7, 2018 19:47
-
-
Save foobit/08c986a7547e14ba2bc1645140e6407b to your computer and use it in GitHub Desktop.
returns Task<T>.Result when "T" can not be provided at compile time
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
public static class TaskExtensions | |
{ | |
public static object GetResult(this Task task) | |
{ | |
task.Wait(); | |
var taskType = task.GetType(); | |
var resultProperty = taskType.GetProperty("Result"); | |
return resultProperty?.GetValue(task); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment