CommunityToolkit / CommunityToolkit/dotnet
ObservableProperty source generator messes up named arguments for attributes assigned with property:attribute
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 400
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
When adding a custom attribute using [property:MyAttribute] the ObservableProperty source generator does not generate named arguments passed to the attributes constructor.
### Regression
_No response_
### Steps to reproduce
1. Custom attribute with optional constructor arguments
```cs
public sealed class PropertyListIncludeAttribute : Attribute
{
public string? Category { get; private init; }
public string? Label { get; private init; }
public PropertyListIncludeAttribute(string? label = null, string? category = null)
{
Label = label;
Category = category;
}
}
```
2. Usage with ObservableProperty
```cs
[ObservableProperty]
[property: PropertyListInclude(category: "Another Category")]
private int testInt;
```
3. See problem in source generated result
```cs
///
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.3.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::DotNetElements.DevTools.SDK.Core.PropertyListIncludeAttribute("Another Category")]
public int TestInt
{
get => testInt;
set
{
if (!global::System.Collections.Generic.EqualityComparer.Default.Equals(testInt, value))
{
OnTestIntChanging(value);
OnTestIntChanging(default, value);
OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.TestInt);
testInt = value;
OnTestIntChanged(value);
OnTestIntChanged(default, value);
OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.TestInt);
}
}
}
```
### Expected behavior
Named arguments need to be properly passed to the source generator
```cs
[global::DotNetElements.DevTools.SDK.Core.PropertyListIncludeAttribute(category:"Another Category")]
```
### Screenshots
_No response_
### IDE and version
VS 2022
### IDE version
_No response_
### Nuget packages
- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [x] CommunityToolkit.Mvvm (aka MVVM Toolkit)
### Nuget package version(s)
8.3.2
### Additional context
_No response_
### Help us help you
No, just wanted to report this
Contributor guide
Assessment
This issue has not been assessed yet.