C# Source Generators | On .NET | Channel 9
source link: https://channel9.msdn.com/Shows/On-NET/C-Source-Generators?WT_mc_id=DOP-MVP-4025064
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Build with an Azure free account. Get USD200 credit for 30 days and 12 months of free services.
Start free todayC# Source Generators
Description
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?
Useful Links
Embed
Download
The Discussion
-
Paula Scholz
Could the [AutoNotify] attribute be modified to add serialization attributes to properties during generation?
Also, can you stack attributes? For example, can I do this?
public class Test
{
[AutoNotify]
[AutoEquality]
private int _id;
}
generates
[DataContract]
public class Test : INotifyPropertyChanged
{
....INotifyPropertyChanged stuff......
[DataMember]
public int Id
{
get { return _id; }
set { ...INotifyPropertyChanged stuff }
}
.... Equality stuff....
} -
so basically u end up with 2 files the on you type, and 1 is auto generated. what do u do in the rest of the project? reference only the auto generated file?
what is the necessary project setup to support this?
Add Your 2 Cents
- Name
- Or Sign In
- Comment
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK