[Bug] RelayCommand Source Generator Fails Silently for Methods Starting With ‘On'
还没有人认领这个 Issue。
评估
调研方向
Start with the RelayCommand source generator and the name-handling path for methods beginning with On. Reproduce the issue using the provided TestViewModel and binding, then compare the generated property name with the documented behavior. Done means OnPointerPressed generates PointerPressedCommand and the Avalonia binding compiles.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
Methods annotated with [RelayCommand] whose names start with On fail to generate command properties.
The documentation states that:
The name of the generated command will be created based on the method name. The generator will use the method name and append "Command" at the end, and it will strip the "On" prefix, if present. Additionally, for asynchronous methods, the "Async" suffix is also stripped before "Command" is appeneded.
However, the actual behaviour I am experiencing contradicts this claim.
Regression
No response
Steps to reproduce
Prerequisites:
- .NET 10
- C# 13
- Create a new Avalonia (Ver. 12.1.3) desktop project. Your project file should include:
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
-
Add the
CommunityToolkit.Mvvm(Ver. 8.4.2) NuGet package. -
Create a ViewModel with
[RelayCommand]methods starting withOn.
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Diagnostics;
namespace MyTestApp.Avalonia.ViewModels;
public partial class TestViewModel : ObservableObject
(etc.)
[RelayCommand]
private void OnPointerPressed()
{
Debug.WriteLine("Pointer pressed.");
}
[RelayCommand]
private void AsdfPointerPressed()
{
Debug.WriteLine("Pointer pressed.");
}
- Create a
TestView. Attempt to bind toOnPointerPressedCommand.
<Window
x:Class="MyTestApp.Avalonia.Views.TestView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyTestApp.Avalonia.ViewModels"
Name="TestView"
x:DataType="vm:TestViewModel">
<!-- This binding will fail to compile. -->
<Button Command="{Binding OnPointerPressedCommand}" />
<!-- This binding will compile successfully. -->
<Button Command="{Binding AsdfPointerPressedCommand}" />
</Window>
Expected behavior
In the ViewModel, [RelayCommand] private void OnPointerPressed() { } would generate a PointerPressedCommand property, which the View could then execute.
Screenshots
No response
IDE and version
VS 2022
IDE version
18.10.2
Nuget packages
- CommunityToolkit.Common
- CommunityToolkit.Diagnostics
- CommunityToolkit.HighPerformance
- CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.4.2
Additional context
No response
Help us help you
No, just wanted to report this
- 主要语言
- C#
- 星标
- 3.8k
- 派生
- 403
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CommunityToolkit/dotnet 的其他 Issue
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicate可能已有人在做 @apachezy 于 92 天前认领。 未关闭bug :bug:
难度 2/5 1-3 小时 新手友好度 84/100
CommunityToolkit/dotnet#1206 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
难度 1/5 1 小时以内 新手友好度 68/100
CommunityToolkit/dotnet#648 ·
-
难度 5/5 一周以上 新手友好度 35/100
CommunityToolkit/dotnet#1217 ·
-
Add segmented buffering and sequence reads to `ArrayPoolBufferWriter<T>`可能已有人在做 @paulomorgado 于 30 天前认领。 未关闭feature request :mailbox_with_mail:
难度 5/5 一周以上 新手友好度 45/100
CommunityToolkit/dotnet#1214 ·
查看 CommunityToolkit/dotnet 的全部 Issue
相似的 Issue
-
good first issue help wanted
难度 2/5 1-3 小时 新手友好度 65/100
-
untriaged
难度 2/5 1-3 小时 新手友好度 72/100
dotnet/dotnet-api-docs#13210 ·
维护者通常 1 天内回复
-
aspnet-core/svc doc-enhancement mvc/subsvc Pri2
难度 2/5 1-3 小时 新手友好度 72/100
dotnet/AspNetCore.Docs#38016 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
HicServices/RDMP#2398 ·
-
area-drawing platform/android t/bug
难度 2/5 1-3 小时 新手友好度 70/100
dotnet/maui#39676 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复