Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: I've built C# source code generator Fluent API library (github.com/npodbielski)
1 point by npodbielski 12 days ago | hide | past | favorite | discuss
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...





Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: