rrmanzano / maui-bindableproperty-generator

Source generator that automatically transforms fields into BindableProperties that can be used in MAUI
MIT License
135 stars 10 forks source link

Partial method call for OnChange #12

Closed paulvarache closed 1 year ago

paulvarache commented 1 year ago

The MVVM Community Toolkit has a source generator for Observable properties that offers a similar experience to this plugin.

It did add a neat feature recently that I would love to have in this plugin. The generator defines a partial method for each property with the attribute, leaving the developer the option to implement said partial method to react to property changes. This is the type of experience you get in Visual Studio:

image

Currently the OnChange property in the Attribute options requires this syntax:

[AutoBindable(OnChange = nameof(OnMyPropertyChanged))]
readonly int _myProperty;

void OnMyPropertyChanged() {}

With partial methods calls generated, it would looks like this:

[AutoBindable]
readonly int _myProperty;

partial void OnMyPropertyChanged(int value) {}
partial void OnMyPropertyChanging(int value) {}

I would also envision adding the changing variant of the property change event.

Pros:

Cons:

rrmanzano commented 1 year ago

This new feature was published in version 0.11.0, Thanks @paulvarache for your great contribution. https://github.com/rrmanzano/maui-bindableproperty-generator/releases/tag/0.11.0