Where in the .NET Source Code are keywords defined


I’m browsing the .NET source code reference (https://referencesource.microsoft.com/) in an effort to find the codefiles in which keywords are defined. Specifically, I’m interested in how await in the TPL is defined/implemented, but I’d also like to browse the internal implementation of other keywords at some time.

Doing a search for the string "await" on their reference site above only returns class, property, and field names that contain the string "await" (e.g., class AwaitTaskContinuation).

I realize this seems like a basic question, but I can’t find any information elsewhere on this.

>Solution :

https://referencesource.microsoft.com/ provides source code for the .NET Framework libraries (for .NET Core use https://source.dot.net/) it does not "define" keywords.

In particular case of await – it is syntactic sugar which is handled by the compiler (Roslyn) and you can try to search how it desugars it to actual code in the github repo.

Or (I would say better, at least in the beginning) use some C# decompilation tool. There is online one https://sharplab.io/ (handles decompilation to C#, IL and even JIT Asm) – example decompilation for the following code:

using System.Threading.Tasks;
public class C {
    public async Task M() => await Task.Yield();

Leave a ReplyCancel reply