12

C# Source Generators | On .NET | Channel 9

 3 years ago
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.
neoserver,ios ssh client
C# Source Generators

Build with an Azure free account. Get USD200 credit for 30 days and 12 months of free services.

Start free today

C# Source Generators

14:45

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

  • User profile image 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....

    }

  • Amirsas

    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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK