3 ms·
Couldn't these also be done in C# via source generators?
by CharlieDigital 3y ago
Couldn't these also be done in C# via source generators?
- AlexErrant 3y agoNo. > How do Source Generators compare with Type Providers in F#? > If you’re an F# programmer (or familiar with the language), then you might have heard of Type Providers. Source Generators were inspired in part by Type Providers, but there are several differences that make them distinct. The main difference is that Type Providers are a part of the F# language proper and emit types, properties, and methods in-memory based on an external source. Source Generators are a compiler feature that analyzes C# source code, optionally with other files, emits C# source code to include back into a compilation. https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/ https://devblogs.microsoft.com/dotnet/introducing-c-source-g...
- CharlieDigital 3y agoI get that the mechanisms are different, but the end result is the same. Edit: sample here with a JSON template: https://github.com/CharlieDigital/dn7-source-generators https://github.com/CharlieDigital/dn7-source-generators
- AlexErrant 3y agoAh, okay I thought that source generators had more limitations compared to F#. Turns out they can make arbitrary calls, including across a network, which previously I thought was only in the domain of type providers: > For Schema.NET, we do a HTTP request to get the JSON we need to build https://turnerj.com/blog/the-pain-points-of-csharp-source-generators https://turnerj.com/blog/the-pain-points-of-csharp-source-ge... Also phillipcarter says yes so I'll happily take his view over mine.
- phillipcarter 3y agoYes. The mechanisms are very different of course, but both the F# and C# components involved generate types with properties, methods, etc. that can populate IntelliSense.