Cat-Lips / GodotSharp.SourceGenerators

C# source generators for the Godot Game Engine
MIT License
127 stars 13 forks source link

Add [Notify] for partial auto-properties. #86

Closed willnationsdev closed 1 week ago

willnationsdev commented 1 week ago

This (in theory) allows you to use .NET 9's partial auto-properties to generate default behavior.

A declaration like so:

public partial class MyNode : Node
{
    // Minimal example
    [Notify]
    public partial float Value1 { get; set; }

    // Complex example:
    // - Additional modifiers are preserved (like "virtual").
    // - Access modifiers of get/set are preserved ("protected get;").
    // - Omitted implementations are likewise omitted in the output (no "set").
    [Notify]
    public partial virtual float Value2 { protected get; }
}

Should generate this:

// Minimal example
#if NET9_0_OR_GREATER
    public partial float Value1
    {
        get => _value1.Get();
        set => _value1.Set(value);
    }
#endif

// Complex example
#if NET9_0_OR_GREATER
    public partial virtual float Value2
    {
        protected get => _value2.Get();
    }
#endif

Unfortunately, it's not clear to me how I'm supposed to actually test the implementation nor how I might write, build, & execute a formal test class/scene to verify the behavior. Was hoping you could provide guidance on that or review/verify the implementation yourself.

Cat-Lips commented 1 week ago

Very good. Thanks for that - I'll merge it in and add some tests.

Cat-Lips commented 1 week ago

All done. New pre-release uploaded :)