Skip to content

MVVMTK0042 code fix does not work for fields with additional attributes (e.g. NotifyPropertyChangedFor) #1007

Closed

Description

@bretthysuik

Describe the bug

MVVMTK0042 code fix does not work for fields with additional attributes (e.g. NotifyPropertyChangedFor)

Regression

No response

Steps to reproduce

Before MVVMTK0042 code fix:

public partial class Class1 : ObservableObject
{
    [ObservableProperty, NotifyPropertyChangedFor(nameof(Age))] private string _name = String.Empty;
    [ObservableProperty] private int _age;
}

After MVVMTK0042 code fix is applied to the project:

public partial class Class1 : ObservableObject
{
    [ObservableProperty, NotifyPropertyChangedFor(nameof(Age))] private string _name = String.Empty;
    [ObservableProperty]
    public partial int Age { get; set; }
}

_name is not automatically converted to a public partial property along with _age.

Expected behavior

Fields with attributes in addition to [ObservableProperty] are automatically converted when the MVVMTK0042 code fix runs.

public partial class Class1 : ObservableObject
{
    [ObservableProperty, NotifyPropertyChangedFor(nameof(Age))] public partial string Name { get; set; } = String.Empty;
    [ObservableProperty] public partial int Age { get; set; }
}

Screenshots

No response

IDE and version

VS 2022 Preview

IDE version

v17.13.0 Preview 1.0

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.4.0-preview2

Additional context

No response

Help us help you

No, just wanted to report this

Activity

  1. added
    bug 🐛An unexpected issue that highlights incorrect behavior
    on Nov 26, 2024
  2. added
    analyzer 👓A new analyzer being implemented or updated
    and removed
    bug 🐛An unexpected issue that highlights incorrect behavior
    on Nov 27, 2024
  3. Sergio0694 commented on Nov 27, 2024

    @Sergio0694
    Member

    This is expected, I only added support for one attribute per list, as I thought using multiple attributes would be more niche. But I suppose it's common enough that it's worth doing the additional work to support it. I'm doing this in a follow up, thank you for opening the issue! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    analyzer 👓A new analyzer being implemented or updatedmvvm-toolkit 🧰Issues/PRs for the MVVM Toolkit

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions