Skip to content

Instantly share code, notes, and snippets.

@foobit
Created October 7, 2018 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foobit/08c986a7547e14ba2bc1645140e6407b to your computer and use it in GitHub Desktop.
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
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