DEV Community

Discussion on: The pain points of C# source generators

turnerj profile image
James Turner Author

Thanks! I haven't done any major checks to performance from using source generators though I could speculate to some IDE performance improvements. IntelliSense wouldn't need to run on all these files as they no longer sit in the repo. Also, performance with Git would be a little better with less files (especially on GitHub where browsing commits that modified these files previously was a big pain).

We switched to source generators for Schema.NET as our previous tooling was a dedicated console application that manually wrote files that stored them in out Git repo. Loading the solution in Visual Studio would take a bit longer from all these extra files it had to process. The code itself behind our tooling that generated the few hundred classes was also in need of a good refactor to set us up for future features. Ultimately we were generating sources that we didn't want in our repo anymore and source generators just fit the bill for what we wanted.

Source generators are probably most useful for when they can accelerate a previously tedious task during development - basically we are getting code to write code. One example that looks really interesting is generating serializers at compile time to improve performance. Normally a serialization system would need to use reflection to generate a serializer for a particular type. Instead with source generators, you could have the serializers generated as part of the compilation step.

As for how I learnt all of this - some is keeping up-to-date with new features coming to C# and .NET (normally from other devs on Twitter) but most is just experimenting and getting more experienced with different aspects that interest me. This was my first time using source generators and I did it for making Schema.NET work better. I work on Schema.NET because it can help my business work better. Basically I'm trying to solve problems down the stack I depend on.

Hope that helps!

arthus15 profile image
Jairo Blanco


Thanks for your answer it really helps me to understand better :D!

I will keep an eye on your future posts!