C# Source Generators

  Рет қаралды 29,798

dotnet

dotnet

Күн бұрын

The source generators feature was adding in .NET 5. They allow you to do interesting things like generate additional source files that will get added to a compilation.
In this video, Kathleen chats with Jared Parsons to find out what source generators are capable of.
[01:15] - What are Source Generators?
[05:24] - Demo: Real-time code generator for classes
[10:54] - Demo: Generating INotifyPropertyChanged
[13:16] - How to learn about building generators?
Introducing Source Generators
devblogs.micro...
Source Generators Cookbook
github.com/dot...
New C# Source Generator samples
devblogs.micro...
Source Generator Samples
github.com/dot...
What’s new in .NET 5
docs.microsoft...
Get your questions answered on the Microsoft Q&A for .NET - aka.ms/dotnet-qa​
Learn .NET with free self-guided learning from Microsoft Learn: aka.ms/learndotnet
#DotNet #Csharp

Пікірлер: 35
@zbecknell
@zbecknell 3 жыл бұрын
These are great. We are already using a couple of custom source generators to auto-register gRPC services marked with an attribute... looking forward to see what the community and the folks at Microsoft cook up over time!
@snapman218
@snapman218 3 жыл бұрын
God, Kathleen interrupting is annoying.
@leonardomoreno23
@leonardomoreno23 Жыл бұрын
Yesss I got distracted all the time.
@shaicohen2
@shaicohen2 3 жыл бұрын
Kathleen you are an amazing host; excellent follow ups. Your passion for source generators shone through! This is an amazing feature! I already have a bunch of ideas I'll probably never get to....
@Kooshad1
@Kooshad1 2 жыл бұрын
it didn't seem to match the guy trying to demo/teach to us though, and she keeps interrupting.
@TheSiddhaartha
@TheSiddhaartha 3 жыл бұрын
Brilliant! Nice examples! I'm going to use this feature a lot!
@a-s733
@a-s733 Жыл бұрын
Great examples. Thank You both...
@positronalpha
@positronalpha 3 жыл бұрын
Ah, it's fully supported by VS now? Awesome! I wrote a generator right after the release and it was not a great experience :).
@Deltacasper
@Deltacasper 10 ай бұрын
How can I use it to generate fake test data based on the bogus framework that is implemented in a class file that generate test data for each entity model and then write it as a file to source code so it can be checked into a git commit?
@rishabhwadhawan541
@rishabhwadhawan541 3 жыл бұрын
Can i use this and generate unit test code for my source code .? Or can i write a generator that would be able to do so.?
@chrishaddox5078
@chrishaddox5078 3 жыл бұрын
I would like to use something like this to help normalize different developers on our teams code. So many times each developer writes something that looks completely different than everyone else. I like like to use this to help reinforce certain patterns in our application
@excitingfruit
@excitingfruit Жыл бұрын
That’s what linters are for
@sujalgupta6177
@sujalgupta6177 3 жыл бұрын
Video is very important
@tristanbellingham6759
@tristanbellingham6759 3 жыл бұрын
I wonder how it will compare to the ReSharper code generator
@scdecade
@scdecade 2 жыл бұрын
T4 has been a real pain. This is interesting
@IIARROWS
@IIARROWS 3 жыл бұрын
So every class and field has a bunch of utterly useless attributes to them? Great way to keep the IL small.
@Kirides
@Kirides 3 жыл бұрын
You have access to the source tree. Attributes are just the easiest way to accomplish that functionality. If you wanted you could use comments or anything else. (SyntaxNode trivia)
@andreasdiermeier8485
@andreasdiermeier8485 3 жыл бұрын
Looking forward to use the new Source Generators. We are using the T4-Templates atm.
@grumpydeveloper69
@grumpydeveloper69 3 жыл бұрын
Nice explanation of integrating source generators but I feel the equals example is not that usefull for complex business objects. As soon as there is 1 property that should not be included in the is equal the generator becomes useless, unless you can decorate the properties to be included or excluded. But that can turn out to replace boilerplate code with a lot of decorators.
@onishirox
@onishirox 3 жыл бұрын
This is amazing, generators can be really useful for repetitive code
@ibrahimhussain3248
@ibrahimhussain3248 3 жыл бұрын
Wow!!
@dakotapearl0
@dakotapearl0 3 жыл бұрын
I'm a bit disappointed to not see the AutoEquality generator in the samples. That's the one that really interested me. Is it not ready or is there another reason that it was not included in the samples ? Thanks and great feature. I'm really looking forward to what people produce with this.
@niton6474
@niton6474 3 жыл бұрын
Uh finally c# gets a Lombok
@psychotrout
@psychotrout 3 жыл бұрын
Nice stuff, thank you!
@tomkirbygreen
@tomkirbygreen 3 жыл бұрын
Magic. Thank you for investing in this! Kudos to all involved in the Generators effort.
@AlvaroRivoir
@AlvaroRivoir 3 жыл бұрын
What if I want to document the notify property?
@krigrtrue
@krigrtrue 3 жыл бұрын
So is this feature ment to make it easy to do AOP in .net?
@ulfandersson1732
@ulfandersson1732 3 жыл бұрын
I have learned not to use the IS operator because it strives for a bad design. What do you think about this and can we use different design implementations for this such as the visitor pattern or are we stuck with the IS operator in this context?
@IIARROWS
@IIARROWS 3 жыл бұрын
I'm interested, what kind of bad design?
@ulfandersson1732
@ulfandersson1732 3 жыл бұрын
​@@IIARROWS Hi, instead of having the implementation of all types in one method with if-statements you can refactor this into virtual methods into a dispatch/visitor-class that implements individual types with method signatures (open/closed principle). Ex. DoSomething(T entity) and do this for all types. It will also reduce the code noise - less code you want to see among other code in that context, like normalizing a relational database. For more information google Design Patterns and Design Principles (SOLID)! You'll be amazed how few patterns and principles needed. And by the way this is design without any specific prog.language, maybe except assembler :).
@IIARROWS
@IIARROWS 3 жыл бұрын
@@ulfandersson1732 A visitor pattern is not always applicable, like when the object doesn't know about who needs it. Besides it isn't much more readable with an `is`, and there are times a centralised option is preferred. I'm not convinced, but I will consider a visitor next time I need to do something similar. :) But remember that in .NET calling a method requires a pretty big impact on performance, while the "is" operator doesn't even do any boxing operation.
@FiveNineO
@FiveNineO 3 жыл бұрын
This will be very useful. Suddenly records seem a little less useful though 🙂
@francoismouchati8189
@francoismouchati8189 3 жыл бұрын
I don't like magic. I like the idea of writing code that generates code but I want to see the generated coffee in the place where it would have been if I had actually typed it. VS should have console windows to type code that generates code. Like snippets but more advanced.
@worldisone2429
@worldisone2429 3 жыл бұрын
Data Annotations will slow down the code
@IIARROWS
@IIARROWS 3 жыл бұрын
I don't think about slowing it down (unless using a lot of reflection, maybe), but creating larger files for sure...
Building microservices with Tye
22:56
dotnet
Рет қаралды 10 М.
All About C# Source Generators | .NET Conf 2023
27:59
dotnet
Рет қаралды 26 М.
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 7 МЛН
HAH Chaos in the Bathroom 🚽✨ Smart Tools for the Throne 😜
00:49
123 GO! Kevin
Рет қаралды 15 МЛН
Players vs Corner Flags 🤯
00:28
LE FOOT EN VIDÉO
Рет қаралды 68 МЛН
Крутой фокус + секрет! #shorts
00:10
Роман Magic
Рет қаралды 19 МЛН
Using Source Generators for Fun (and Maybe Profit)
29:00
dotnet
Рет қаралды 20 М.
C# 9 Language Features
22:39
dotnet
Рет қаралды 62 М.
Coding Shorts: Building a Source Generator - Part 1
17:31
Shawn Wildermuth
Рет қаралды 9 М.
10 C# Libraries To Save You Time And Energy
33:59
IAmTimCorey
Рет қаралды 207 М.
C# Source Generators Tutorial
48:58
Raw Coding
Рет қаралды 25 М.
C# Source Generators - Write Code that Writes Code
28:36
dotnet
Рет қаралды 49 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 197 М.
Thoughts About Unit Testing | Prime Reacts
11:21
ThePrimeTime
Рет қаралды 225 М.
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 7 МЛН