[Bug] RelayCommand Source Generator Fails Silently for Methods Starting With ‘On'
まだ誰も着手していません。
評価
調査の方向性
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
- フォーク
- 400
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
CommunityToolkit/dotnet のほかの issue
-
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 ·
-
feature request :mailbox_with_mail:
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
CommunityToolkit/dotnet#1214 ·
-
bug :bug:
難易度 4/5 3〜5日 初心者へのやさしさ 58/100
CommunityToolkit/dotnet#1208 ·
CommunityToolkit/dotnet の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/fluentui-blazor#5364 ·
メンテナーはふだん 1 日以内に返信
-
.NET triage
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
microsoft/agent-framework#8811 ·
メンテナーはふだん 1 日以内に返信
-
.NET Docs
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
getsentry/sentry-dotnet#5637 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
QuantConnect/Lean#9842 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
NethermindEth/nethermind#14012 ·
メンテナーはふだん 1 日以内に返信