4 ms·
Show HN: I've built ORM-ish library using dotnet source generator
I wanted to evaluate C# source generators to see whether "compile time PetaPoco like" project can be built with it.
- CharlieDigital 3y agoC# source generators are a really pretty amazing and under-appreciated platform tooling on .NET. I suppose with the shift towards AOT, folks should get familiar with it. I found the DX with it to be quite tricky (at least in Visual Studio Code) as it was difficult to log or trace through the code what was happening and what was going wrong. Microsoft's documentation is also quite lacking. Do you have any write up or tips on the DX? It's a pretty impressive project and I'm really interested in how to improve my own workflow with respect to source generators since my experience has been that they are clumsy to work with.
- dgpy 3y agoThanks. Personally, I found that most efficient way to develop source generators was by utilizing in memory compilation in unit tests. That way, I was able to use debugger to understand AST provided by Roslyn and quickly iterate. Not sure how it works within VSCode but in Rider it was really fine. Also, sometimes Visual Studio and Rider doesn't regenerate code (likely because internally msbuild decides that dlls are up-to-date). Unit test + in memory compilation way described above assured that latest code was really used in test.
- CharlieDigital 3y ago> That way, I was able to use debugger to understand AST provided by Roslyn and quickly iterate. Interesting; would love to see a video of your workflow and process. With VSC, I found that I had to do some "hacks" to drop output as comments into a generated file so I could see what was happening.
- dgpy 3y agoGeneral usage is as in this short video: https://streamable.com/3oqxhf https://streamable.com/3oqxhf `QueryGeneratorTestUtil.GenerateCompileAndAssert` internally uses `Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create()` and `Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create()`. I get an interactive, debuggable source generator development environment this way. Same as you, initially I used "comments as debugging" hacks but above way is way more efficient.
- owlstuffing 3y agoNice. The manifold-sql project[1] is similar, but goes a bit further with complete type-safe native SQL support. [1] https://github.com/manifold-systems/manifold/blob/master/manifold-deps-parent/manifold-sql/readme.md https://github.com/manifold-systems/manifold/blob/master/man...