dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

[Feature] Specify the generated ObservableProperty name

Open blueshift777 opened this issue 1 year ago • 1 comments

I would like to contribute an update to the ObservableProperty attribute that would allow the user to specify the resulting property name. This would involve adding a string property, SpecifiedPropertyName, to the ObservableProperty attribute class in addition to a new, overloaded constructor that accepts the specified property name as a parameter. If the SpecifiedPropertyName is not null or whitespace, the property with the specified name is generated. Otherwise, the current method for generating the property name will be used. For example,

[ObservableProperty("SpecialValue")]
private double value;

will generate the observable property,

public double SpecialValue
{
    get => value;
    set
    {
        if (!global::System.Collections.Generic.EqualityComparer<double>.Default.Equals(this.value, value))
        {
            OnSpecialValueChanging(value);
            OnSpecialValueChanging(default, value);
            OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.SpecialValue);
            this.value = value;
            OnSpecialValueChanged(value);
            OnSpecialValueChanged(default, value);
            OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.SpecialValue);
        }
    }
}

The purpose of this feature is to allow users to specify the property name when the private member variable does not follow common naming conventions.

blueshift777 avatar Nov 14 '23 00:11 blueshift777

Hello blueshift777, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Nov 14 '23 00:11 ghost

Duplicate of #706. Superseded by #555.

This is also a duplicate of #835, please avoid opening the same proposal multiple times 🙂

Sergio0694 avatar Aug 21 '24 20:08 Sergio0694