Open juwens opened 1 year ago
I think it makes a lot of sense. While I like having properties defined inside the class block, having to declare an unused field requires turning off some compiler warnings.
It should be possible to implement this without breaking the existing attribute and either offer both options or provide a transition period for developers to adapt
How do you think if the generator will base on the handler methods?
e.g.
// ControlX.properties.cs
partial class ControlX {
[AutoBindable<bool>]
private static void HandlePropertyXChanged(BindableObject obj, object oldValue, object newValue) {}
private static void HandlePropertyXChanging(BindableObject obj, object oldValue, object newValue) {}
[AutoBindable<string>()]
private static void HandlePropertyYChanging(BindableObject obj, object oldValue, object newValue) {}
}
The generator will generate
// ControlX.g.cs
partial class ControlX {
public static BindableProperty PropertyXProperty = BindableProperty.Create(
nameof(PropertyX),
typeof(ControlX),
typeof(bool),
true,
propertyChanged: HandlePropertyXChanged,
propertyChanging: HandlePropertyXChanging
);
public bool PropertyX {
get => (bool)GetValue(PropertyXProperty);
get => SetValue(PropertyXProperty, value);
}
public static BindableProperty PropertyYProperty = BindableProperty.Create(
nameof(PropertyY),
typeof(ControlX),
typeof(string),
default,
propertyChanging: HandlePropertyYChanging
);
public string PropertyY {
get => (string)GetValue(PropertyYProperty);
get => SetValue(PropertyYProperty, value);
}
}
And we should remove MAUI dependency because with .NET6/C# 10, we can use global usings
for namespaces in generated code
This :
Instead of this:
Advantage:
Downside: