This post looks at how to use C# Source Generators to build an external DSL to represent mathematical expressions. The code for this post is on the roslyn-sdk repository . A recap of C# Source Generators There are two other articles describing C# Source Generators on this blog, Introducing C# Source Generators and New C# Source Generator Samples . If you’re new to generators, you might want to read them first. Let’s just remind ourselves of what they are. You can think of a Source Generator as a function that runs at compile time. It takes some inputs and produces C# code. Program Parse Tree -> Additional Files -> File Specific Options -> C# Code This conceptual view is implemented in the ISourceGenerator interface. public interface ISourceGenerator { void Execute(GeneratorExecutionContext context); void Initialize(GeneratorInitializationContext context); } You implement the Execute method and get the inputs through the context object. The Init...
Free tutorials, courses, generative tools, and projects built with Javascript, PHP, Android, Python, ML, AI, VR, ChatGPT, .Net, C#, Java, Microsoft, Kotlin, Youtube, Github Code Download and more.