Created
October 21, 2018 10:58
-
-
Save mariusGundersen/b552f99f4f2703a00b461c1ce4d11df0 to your computer and use it in GitHub Desktop.
Duct-typed extension methods, example 2
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
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