Skip to content

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

Closed

Description

@GetGet99

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

Activity

  1. added
    bug 🐛An unexpected issue that highlights incorrect behavior
    on Jun 1, 2023
  2. moved this to 📋 Backlog in 8.2.1on Jun 1, 2023
  3. moved this from 📋 Backlog to 🏗 In progress in 8.2.1on Jun 20, 2023
  4. moved this from 🏗 In progress to ✅ Done in 8.2.1on Jun 21, 2023
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

    bug 🐛An unexpected issue that highlights incorrect behaviormvvm-toolkit 🧰Issues/PRs for the MVVM Toolkit

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions