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

Observable Property used on a field with escaped name is not generating correctly #710

Closed
1 of 4 tasks
GetGet99 opened this issue Jun 1, 2023 · 0 comments · Fixed by #720
Closed
1 of 4 tasks
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit

Comments

@GetGet99
Copy link

GetGet99 commented Jun 1, 2023

Describe the bug

Observable Property used on a field with an escaped name (the name starting with the @ sign such as @event @param @int) is not generating correctly.

Steps to reproduce

  1. Create a project with the MVVM Toolkit installed
  2. Add in this code snippet
[ObservableProperty]
double @event;
  1. Type Event somewhere in a method and Ctrl + Click it to go to the definition
  2. The output should look like this
/// <inheritdoc cref="event"/>
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public double Event
{
    get => event;
    set
    {
        if (!global::System.Collections.Generic.EqualityComparer<double>.Default.Equals(event, value))
        {
            OnEventChanging(value);
            OnEventChanging(default, value);
            OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.Event);
            event = value;
            OnEventChanged(value);
            OnEventChanged(default, value);
            OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.Event);
        }
    }
}

Expected behavior

Every single event in the generated code should be replaced with @event because event is treated as a C# keyword.

/// <inheritdoc cref="@event"/>
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public double Event
{
    get => @event;
    set
    {
        if (!global::System.Collections.Generic.EqualityComparer<double>.Default.Equals(@event, value))
        {
            OnEventChanging(value);
            OnEventChanging(default, value);
            OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.Event);
            @event = value;
            OnEventChanged(value);
            OnEventChanged(default, value);
            OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.Event);
        }
    }
}

Screenshots

image

IDE and version

VS 2022

IDE version

17.6.2

Nuget packages

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

Nuget package version(s)

8.2.0

Help us help you

No, just wanted to report this

@GetGet99 GetGet99 added the bug 🐛 An unexpected issue that highlights incorrect behavior label Jun 1, 2023
@Sergio0694 Sergio0694 added the mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit label Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants