dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Add Specified Property Name Overload to ObservableProperty Attribute

Open blueshift777 opened this issue 1 year ago • 2 comments

This is my proposed pull-request submission: Update the ObservableProperty attribute by adding an overload that allows the user to specify the property name that is generated from the private member variable.

Change to ObservablePropertyAttribute.cs:

    /// <summary>
    /// Constructor with specified property name
    /// </summary>
    /// <param name="specifiedPropertyName">Specified auto-generated property name</param>
    public ObservablePropertyAttribute(string specifiedPropertyName)
    {
        SpecifiedPropertyName = specifiedPropertyName;
    }

    /// <summary>
    /// Specified auto-generated property name
    /// </summary>
    public string SpecifiedPropertyName { get; private set; } = string.Empty;

Example of changes to ObservablePropertyGenerator.Execute.cs:

            string propertyName = fieldSymbol.Name;
            if (fieldSymbol?.GetAttributes().Any() == true)
            {
                ImmutableArray<AttributeData> attributeDataSet = fieldSymbol.GetAttributes();
                AttributeData? firstAttributeData = attributeDataSet.FirstOrDefault();
                if (firstAttributeData != null)
                {
                    ImmutableArray<TypedConstant> constructorArguments = firstAttributeData.ConstructorArguments;
                    if (constructorArguments.Any() == true)
                    {
                        TypedConstant? firstConstructorArgument = constructorArguments.FirstOrDefault();
                        if (firstConstructorArgument.HasValue)
                        {
                            string specifiedPropertyName = firstConstructorArgument.Value.Value!.ToString();
                            return specifiedPropertyName;
                        }
                    }
                }
            }

            string? propertyName = fieldSymbol?.Name;

blueshift777 avatar Jan 06 '24 00:01 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 Jan 06 '24 00:01 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Jan 21 '24 01:01 ghost

Is there additional information you need from me regarding this request? Can it receive the requested triage?

blueshift777 avatar Aug 06 '24 01:08 blueshift777

Duplicate of #706. Superseded by #555.

Sergio0694 avatar Aug 06 '24 01:08 Sergio0694