Three months of working with Roslyn
On one hand I'm shocked by the amount of time I've spent on learning how to modify Roslyn, and how little I've actually accomplished. But on the other hand I have learned a lot, and I have achieved my first major goal, to use Roslyn to produce obfuscated C# modules. (And yes, I agree, this is a rather dubious achievement, but I do have some other objectives for future Roslyn modifications.)
So, what have I learned?
- Roslyn is huge. Like 190 Visual Studio projects and 5 million lines of code and other stuff huge. Compiling all of Roslyn causes my development PC to grind to a halt, and take up to 15 minutes to do a complete build. (So for my modification projects I only recompile the C# compiler parts.)
- Roslyn is complicated. The C# code makes extensive use of interfaces and derived classes, partly in order to support both C# and VB compiler processing. Processing is constantly switching between stuff in the CSharpCodeAnalysis and CodeAnalysis modules. This leads to constant frustrations because most of my modifications so far are in the CodeAnalysis module because that's where the final code is emitted to the PE output file. When I trace Roslyn code and look at an object provided via a reference to an interface the Visual Studio debugger helpfully displays all of the object's actual fields. "Ah ha," I say, "there's the field I need to use!" "Sorry," says the C# compiler, "the debugger may know about that field, but I don't - it's defined in a class in CSharpCodeAnalysis."
- Roslyn programmers love immutable objects. I think they're a pain in the ass, presumably because I'm too dumb to understand why immutable objects are so great.
- And speaking of my lack of smarts, another thing that the Roslyn programmers love, and which I simply can't get my head around, is the visitor pattern. It's everywhere, and I hate it because I can't understand it.
- Finally, Roslyn is wonderful. It's big and complicated and difficult (for me, at least) to understand, but it's clearly very well implemented, and does fantastic things. Respect for the programmers who created this amazing piece of technology. I look forward to my continuing adventures in modifying Roslyn.
- (One example of how wonderful and flexible Roslyn can be once you've figured it out: It took only about 50 lines of code to modify Roslyn so it could optionally produce two output modules instead of one for each C# compilation!)
Making my Roslyn modifications available
In a previous article I promised (threatened?) to make my Roslyn modifications available via GitHub. But I've never really taken a shine to Git (sorry, Linus), so I've decided instead to make them available via my company's FTP server. You can find them here:
They're currently hidden away under "Utility programs". If/when there's ever any real demand for this stuff I'll try to move them to a more prominent place on the page.
1. Built-in support to make it easier for diagnostic logging programs to pinpoint where in a program they were called from.
2. Built-in support for serializing and deserializing .Net objects.
That should keep me busy for the next year or so, at my present rate of progress.