.NET Esoterica is a living book. It serves as the lost documentation and reference manuals that I wish I had when I began my journey learning some of the more esoteric features and extension points of .NET. Everything in here focuses on the latest .NET technologies - so .NET 7+, not .NET Framework. The only time .NET Framework topics will be covered is when our goal is to target .NET Standard 2.0 (in the case of Source Generators) or we are aiming to create a library that is compatible with the widest audience possible.
Granted, I am still learning new things about these topics every day. Hence, a living book. Contents subject to change.
Roslyn SDK
The first major section will focus on the Roslyn API. This is the way that we will be interacting with the C# compilation process. While we will mostly be focusing on this from a source generator standpoint at first, the information should be applicable to analyzer and code fixes as well. This is because the Roslyn APIs is more a reflection of the C# language design more than anything. Sure, there are some compiler specific quirks and features. Fundamentally we will learn how to view and understand our own code through the lens of the various compilation stages.
Read moreSource generators - .NET meta-programming
This is where I’m currently spending a lot of time doing research. Source generators are an extremely powerful tool in the .NET ecosystem. It takes meta-programming to the next level by allowing us to extend the compiler itself. While it doesn’t necessarily allow us to do things like add new language features and keywords, it still allows us to do a lot. We can remove a large amount of boiler plate code from our code bases. Things that would have been infeasible otherwise are now within our grasp. And now, with some new features in .NET 8 / C# 12 - namely “interceptors” - we have even more power and flexibility.
Read moreMSBuild SDKs
MSBuild can be quite intimidating at first. At least, it was for me. The SDK-style projects used by .NET today greatly simplifies creating projects, but it pushes even more of the build system into a black box. The goal of this section is to open that box and look inside. To understand not just MSBuild, but the “SDK” projects built on top of them.
Read moreInteroping with native code
Lastly, we’ll cover native interoperability in depth. Native interop usually refers to inter-operating to and from C. P/Invoke has traditionally been the mechanism for calling out of managed code and into native. But this is, what I consider, to only be one third of the whole story. Did you know you can call C# code from C code? And now with NativeAOT becoming a first class scenario, doing so has become even easier. Lastly, there’s the exploration of unsafe
code within C#. Despite the name, writing such code does not need to be unsafe. Using it wisely can greatly improve our native interop story to create nice and clean interfaces in both directions.