16
Generating Code
So far in the book, we’ve looked at how powerful metaprogramming can be in .NET at runtime. Doing everything at runtime has the benefit of the flexibility to adapt to things that occur at runtime. The downside of doing this at runtime is that it has a performance impact. This is where the C# Roslyn compiler really shines. We had the capability to generate code in the past with commercial products such as PostSharp (https://www.postsharp.net/) or Intermediate Language (IL) weaving, using projects such as Fody (https://github.com/Fody/Fody) But with Roslyn, code generation has truly been democratized and made easy for anyone to do.
Personally, I’ve worked with all the techniques throughout the years, and finally, with Roslyn, ...
Get Metaprogramming in C# now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.