dotnet
dotnet copied to clipboard
Add Specified Property Name Overload to ObservableProperty Attribute
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;
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 🙌
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.
Is there additional information you need from me regarding this request? Can it receive the requested triage?
Duplicate of #706. Superseded by #555.