Skip to content

[RelayCommand] source generator error with can't lowered first-char #446

@JamesCorl

Description

@JamesCorl

Describe the bug

[RelayCommand] attribute source generator error, for the function-name's first character can't be lowered.

Regression

No response

Steps to reproduce

  1. A Dotnet6 project with MVVM toolkit 8.0.0 installed
  2. A function with its name's first character can't be lowered, such as:
[RelayCommand]
private void 中文() {}
[RelayCommand]
private void c中文() {}
  1. Build and see the error:CS0102 类型“MainViewModel”已经包含“中文Command”的定义.
  2. Generated code snippet that causing the error:
partial class MainViewModel{
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.0.0.0")]
private global::CommunityToolkit.Mvvm.Input.RelayCommand<bool?>? 中文Command;
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.0.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public global::CommunityToolkit.Mvvm.Input.IRelayCommand<bool?> 中文Command => 中文Command ??= new global::CommunityToolkit.Mvvm.Input.RelayCommand<bool?>(new global::System.Action<bool?>(中文));
}

Expected behavior

No error, just like when the function name is changed to "C中文".
Maybe it should use '_' to name the background field instead, because [ObservableProperty] works fine with "_中文".
Expected generated code snippet:

partial class MainViewModel{
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.0.0.0")]
private global::CommunityToolkit.Mvvm.Input.RelayCommand<bool?>? _中文Command;
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.0.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public global::CommunityToolkit.Mvvm.Input.IRelayCommand<bool?> 中文Command => _中文Command ??= new global::CommunityToolkit.Mvvm.Input.RelayCommand<bool?>(new global::System.Action<bool?>(中文));
}

Screenshots

No response

IDE and version

VS 2022

IDE version

VS Community 2022 17.3.4

Nuget packages

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

Nuget package version(s)

8.0.0

Additional context

No response

Help us help you

Yes, but only if others can assist

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

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions