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

ObservableProperty source generator messes up named arguments for attributes assigned with property:attribute #1038

Open
1 of 4 tasks
Felix-CodingClimber opened this issue Jan 5, 2025 · 0 comments
Labels
analyzer 👓 A new analyzer being implemented or updated mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit

Comments

@Felix-CodingClimber
Copy link

Felix-CodingClimber commented Jan 5, 2025

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
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;
    }
}
  1. Usage with ObservableProperty
[ObservableProperty]
[property: PropertyListInclude(category: "Another Category")]
private int testInt;
  1. See problem in source generated result
/// <inheritdoc cref="testInt"/>
[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<int>.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

[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
  • 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

@Felix-CodingClimber Felix-CodingClimber added the bug 🐛 An unexpected issue that highlights incorrect behavior label Jan 5, 2025
@Sergio0694 Sergio0694 added mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit analyzer 👓 A new analyzer being implemented or updated and removed bug 🐛 An unexpected issue that highlights incorrect behavior labels Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer 👓 A new analyzer being implemented or updated mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit
Projects
None yet
Development

No branches or pull requests

2 participants