Skip to content

Instantly share code, notes, and snippets.

@mariusGundersen
Created October 21, 2018 10:58
Show Gist options
  • Save mariusGundersen/b552f99f4f2703a00b461c1ce4d11df0 to your computer and use it in GitHub Desktop.
Save mariusGundersen/b552f99f4f2703a00b461c1ce4d11df0 to your computer and use it in GitHub Desktop.
Duct-typed extension methods, example 2
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
// Example 2: await anything
public static TaskAwaiter<T> GetAwaiter<T>(this T nonAwaitable)
=> Task.FromResult(nonAwaitable).GetAwaiter();
// Now we can write code like this
await "Hello world";
await 100;
await true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment