Writing

Articles on CLR internals, IL, C#, Roslyn, and Mono.Cecil, newest first.

  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.

  2. How to inspect a MethodSpec signature without code

    What a MethodSpec is in .NET metadata, how its signature is encoded in the blob stream, and how to read it with dnSpy or CFF Explorer.

  3. The object header gets complicated

    The CLR object header bit by bit: thin locks, sync block indexes, hash codes, and the difference between thin and fat locks.

  4. 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.

  5. 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.

  6. C# behind the scenes: yield

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

  7. DumpMiner: A UI for exploring ClrMD

    DumpMiner, a WPF tool built on ClrMD for inspecting crash dumps and live .NET processes without memorizing WinDbg and SOS commands.

  8. Mono.Cecil: SimplifyMacros and OptimizeMacros

    What SimplifyMacros and OptimizeMacros do in Mono.Cecil, and why rewriting a method should start with one and end with the other.

  9. Mono.Cecil: Generics

    Importing and instantiating a generic type with Mono.Cecil, and why the method reference’s declaring type must be the generic instance.

  10. Mono.Cecil: IAssemblyResolver

    What IAssemblyResolver does in Mono.Cecil, and why real projects should give the reader one shared, custom resolver.

  11. Mono.Cecil: Nothing stops you (well, almost)

    Mono.Cecil follows the CLI rules rather than the C# rules, so it can do things C# forbids, such as giving a method a name that is illegal in C#.

  12. 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.

  13. Mono.Cecil: Hello, World

    A minimal Mono.Cecil program that creates an assembly from scratch, with one type and a method that prints Hello World.

  14. Mono.Cecil: An overview

    An introduction to Mono.Cecil: what it offers over Reflection.Emit, the difference between references and definitions, and the core types of its object model.

  15. Making a method static with Roslyn

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

  16. 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.

  17. 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.

  18. A low-level global keyboard hook in C#

    A reusable C# class for global low-level keyboard hooks with SetWindowsHookEx, and how to register and remove key combinations.

  19. Localization with ResourceManager

    A localization design for .NET applications built on .resx files and ResourceManager, with one access point that can validate and log missing values.

  20. 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.

  21. 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.

  22. One thing you can do only with a reference type

    Why lock works only on reference types: the object header, the sync block, and what value types lack.

  23. Deadlock vs. livelock

    Two ways threads stop making progress: deadlocked threads wait without using CPU, while livelocked threads keep retrying and burn it.

  24. Rendering XAML as an image for a custom Windows Phone 8 live tile

    Rendering XAML to an image with WriteableBitmap to build custom Windows Phone 8 live tiles, updated periodically by a scheduled agent.

  25. Showing help for the focused WPF control with F1

    Showing context help for the focused WPF control when the user presses F1, using a CommandBinding and an attached property while staying within MVVM.