All About C# Source Generators | .NET Conf 2023

  Рет қаралды 23,480

dotnet

dotnet

7 ай бұрын

While using Reflection is still a necessary tool for any developer. The Roslyn source generators are a compelling way to write code while your users are writing their code. In this talk, Shawn will build a source generator from scratch to show you all the gory details.
www.dotnetconf.net
#DotNet #dotnetconf #dotnet8
🙋‍♀️🙋‍♂️ Get your questions answered on the Microsoft Q&A for .NET: aka.ms/dotnet-qa
🏫 Learn C#, F#, and .NET with free self-guided learning from Microsoft Learn: aka.ms/learndotnet

Пікірлер: 29
@jewersp
@jewersp 7 ай бұрын
Shawn, thank you for this amazing video. I was already familiar with the ISourceGenerator interface as well as with the MVVM Source Generators, but you managed to quickly introduce me to the IIncrementalGenerator interface and how to use it instead of the deprecated ISourceGenerator interface. This has been clear, concise and straight to the point with an easily understandable use case.
@acodersjourney
@acodersjourney 7 ай бұрын
You're a true role model for content creators.
@davidtaylor3771
@davidtaylor3771 7 ай бұрын
Awesome summary Shawn.
@arspin7450
@arspin7450 3 ай бұрын
Great, very useful!!
@being_aslam_tiger
@being_aslam_tiger 7 ай бұрын
Shawn you are the best 💖
@aathifmahir
@aathifmahir 3 ай бұрын
This awesome, would love to see more video regarding some of new async constructs introduce recently in dotnet
@tplummer217
@tplummer217 2 ай бұрын
This is gold!
@raulands
@raulands 7 ай бұрын
Hi Shawn, thanks for your videos. Would generating classes from a database schema be a use case for source generators? So, read the schema from a database and generate classes from it. Thanks!
@zwatotem
@zwatotem 7 ай бұрын
Is there a ready made library, that has the same interface as reflection (or as close as possible) for fetching info about assemblies, types, etc.?
@JuiceRabbit
@JuiceRabbit 7 ай бұрын
Great video! But is there a link to the source code? Thanks!!!
@warrenbuckley3267
@warrenbuckley3267 7 ай бұрын
I'm surprised the example you created compiled without specifying either the fully qualified name of the List or adding the using statement to the top of the generated file.
@patfre
@patfre 7 ай бұрын
The not putting the name is a .NET 6 feature lol (2 years old) as for the using there’s a thing called global usings and List is a part of the standard global usings so maybe look up features more often or use newer versions instead of those old versions which lost support ages ago
@warrenbuckley3267
@warrenbuckley3267 7 ай бұрын
@@patfre Global using statements are fine for an example (such as the example shown by Shawn) but I would not recommend it when building a library as the feature may not be enabled in the consumers project settings. I also find your "lost support ages ago" statement perplexing. Nothing is my original question "lost support ages ago". Last time I checked you can still specify a fully qualified name of a type. In fact libraries which generate code that I've used specify the fully qualified name of a type. It doesn't sound like English is your first language so maybe something just got lost in translation for you.
@patfre
@patfre 7 ай бұрын
@@warrenbuckley3267 I am not saying you cannot I am saying it is a new thing where you don’t have to. Also using old versions is a security risk. Also the compiler has the usings file as it is a auto generated file by a source generator so if you upload it or give it to someone else it will still work so I don’t get your point it’s automatic so just use it you seam to the type who is really scared of change it seams
@hansolololol
@hansolololol 7 ай бұрын
I assume we're not limited to generating C# code right? Could we also generate type serialization schemas or stuff like that?
@GumbootMan
@GumbootMan 7 ай бұрын
C# is the only supported output, which should not be surprising seeing as the source generator code is literally running within the C# compiler process. That said, source generators are arbitrary code and if you want your source generator to directly write files to disk nothing is going to stop you. Just don't expect those additional files to integrate smoothly into the build process. I should mention that the opposite process -- reading a non-C# project file in your source generator and using that to generate C# -- is a supported scenario.
@hansolololol
@hansolololol 7 ай бұрын
@@GumbootMan well, that makes sense, still better than a extra post build step.
@canabale
@canabale 7 ай бұрын
Github link???
@L4rsTrysToMakeTut
@L4rsTrysToMakeTut 7 ай бұрын
Uff cool feature in general but have you looked at macros in Julia Lang? These are way easier, safer and simpler to understand
@swildermuth
@swildermuth 7 ай бұрын
Yeah, but you run into the issue of macros becoming C++ macros which can obuscate everything. The trick here is to allow for code generation during development not just at build time
@L4rsTrysToMakeTut
@L4rsTrysToMakeTut 7 ай бұрын
@@swildermuth I think there is quite a difference. C++ and C# use strings to generate code. Julia is homoiconic that means the language is representable in itself - like lisp
@zumanoka3310
@zumanoka3310 7 ай бұрын
what are these generators for? what can they be useful for?
@MaximilienNoal
@MaximilienNoal 7 ай бұрын
For anything, really. For example, to replace reflection or to generate boilerplate code.
@ajtandon3679
@ajtandon3679 7 ай бұрын
If you want to use native AOT, you have to use source generators as reflection is not allowed since the trimming will not work.
@alikzalikz_
@alikzalikz_ 7 ай бұрын
best example is new boilerplate of Program.cs since .net6.0
@pablopons7611
@pablopons7611 7 ай бұрын
You could write your entities instead of using T4 templates (.tt) for example.
@haxi52
@haxi52 7 ай бұрын
I wrote one that generates interfaces and IOC registration code for my injected services.
@jorgepedraza1275
@jorgepedraza1275 7 ай бұрын
🤔
What's New in C# 12 | .NET Conf 2023
35:28
dotnet
Рет қаралды 54 М.
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 1,6 МЛН
THE POLICE TAKES ME! feat @PANDAGIRLOFFICIAL #shorts
00:31
PANDA BOI
Рет қаралды 24 МЛН
你们会选择哪一辆呢#short #angel #clown
00:20
Super Beauty team
Рет қаралды 13 МЛН
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 9 МЛН
.NET Configuration In Depth | .NET Conf 2023
29:58
dotnet
Рет қаралды 22 М.
Coding Shorts: Building a Source Generator - Part 1
17:31
Shawn Wildermuth
Рет қаралды 9 М.
On .NET Live: Lessons Learned Building Source Generators
59:45
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 252 М.
A Complete .NET Developer's Guide to Span with Stephen Toub
1:02:48
Reverse proxying is easy with YARP | .NET Conf 2023
29:46
dotnet
Рет қаралды 10 М.
Is C++ better than C?
1:46:10
Tsoding Daily
Рет қаралды 41 М.
OOP in Pure C
2:00:13
Tsoding Daily
Рет қаралды 66 М.
OZON РАЗБИЛИ 3 КОМПЬЮТЕРА
0:57
Кинг Комп Shorts
Рет қаралды 443 М.
Неразрушаемый смартфон
1:00
Status
Рет қаралды 2,4 МЛН
Tag her 🤭💞 #miniphone #smartphone #iphone #samsung #fyp
0:11
Pockify™
Рет қаралды 18 МЛН
Choose a phone for your mom
0:20
ChooseGift
Рет қаралды 5 МЛН