Show HN: I've built C# source code generator Fluent API library (github.com)

1 points by npodbielski ↗ HN
I created library that helps creating C# source code generator for Roslyn.

In short it allows to write C# code with nice Fluent API that is context aware:

context.WithClass(Path.GetFileNameWithoutExtension(file.FileName), c => c.WithMethod("Log", m => m.WithBody(b => b.Append($"Console.WriteLine({file.Content.TripleQuote()});"))) );

Which is much easier to write than giant spaghetti of variable, formatted strings.

Original Roslyn APIs are a bit hard to use so this package helps with that. Also it helps with:

- automatically emitting using statements - formatting generated code - with importing types during code generation - with indentation and parenthesis balancing - helps with adding and using method parameters in generated code - `async` methods generation - provides nicer to use wrappers to Roslyn `IncrementalValueProvider` and others - allows to share pieces of code between files/classes (i.e. interfaces implementation)

I put instruction on how to use it on my blog here: https://internetexception.com/2025/10/02/writing-simple-c-so...

Also here is a video of this library working plugged into a project in Rider IDE:

https://internetexception.com/wp-content/uploads/2025/10/cod...

0 comments

[ 3.3 ms ] story [ 13.3 ms ] thread

No comments yet.