Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Specified Property Name Overload to ObservableProperty Attribute #835

Open
blueshift777 opened this issue Jan 6, 2024 · 2 comments
Open
Labels
needs attention 👋 This issue or PR needs attention by maintainers needs triage 🔍 This issue is awaiting triage by maintainers

Comments

@blueshift777
Copy link

blueshift777 commented Jan 6, 2024

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;

@ghost ghost added the needs triage 🔍 This issue is awaiting triage by maintainers label Jan 6, 2024
@ghost
Copy link

ghost commented Jan 6, 2024

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 ghost added the needs attention 👋 This issue or PR needs attention by maintainers label Jan 21, 2024
@ghost
Copy link

ghost commented Jan 21, 2024

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.

@Arlodotexe Arlodotexe transferred this issue from CommunityToolkit/WindowsCommunityToolkit Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs attention 👋 This issue or PR needs attention by maintainers needs triage 🔍 This issue is awaiting triage by maintainers
Projects
None yet
Development

No branches or pull requests

1 participant