C# compiler

What the C# compiler generates from your code: iterator state machines, local functions, the IL it emits for everyday calls and casts, and Roslyn syntax rewriters.

  1. Writing IL according to the specification

    Writing IL that matches what the C# compiler emits: how is, as, casts, and generic constraints turn into box, isinst, and castclass.

    CLR internalsC# compiler6 min read

  2. C# behind the scenes

    The introduction to a series on the code the C# compiler generates for language features such as yield and local functions.

    C# compiler1 min read

  3. C# behind the scenes: Local functions

    How the C# compiler turns local functions into ordinary methods, and how captured variables move into a generated display struct.

    C# compiler3 min read

  4. C# behind the scenes: yield

    How the C# compiler turns an iterator method that uses yield return into a generated state machine class.

    C# compiler5 min read

  5. Value type methods: call, callvirt, constrained, and hidden boxing

    How call, callvirt, and the constrained prefix work for value type methods, and when calling ToString on a struct quietly boxes it.

    CLR internalsC# compiler3 min read

  6. Making a method static with Roslyn

    A Roslyn syntax rewriter that turns an instance method into a static method, with the source on GitHub.

    C# compiler1 min read

  7. What is the @ sign before a variable name?

    What the @ prefix on a C# identifier does, why the compiled name drops it, and how that can break reflection lookups by name.

    C# compiler1 min read

  8. Converting LINQ query syntax to fluent syntax with Roslyn

    A Roslyn syntax rewriter that converts LINQ query comprehension syntax into the equivalent fluent method calls.

    C# compiler1 min read

  9. IL call vs. callvirt, part two

    When the C# compiler emits call instead of callvirt, such as for static methods, struct methods, and calls on a newly created object, shown in IL and disassembly.

    CLR internalsC# compiler2 min read

  10. IL call vs. callvirt

    Why the C# compiler emits callvirt even for non-virtual methods: the difference between call and callvirt, and the null check that callvirt provides.

    CLR internalsC# compiler4 min read