[Bug] RelayCommand Source Generator Fails Silently for Methods Starting With ‘On'
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- C#
- Stelle
- 3.8k
- Fork
- 401
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CommunityToolkit/dotnet
-
bug :bug:
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
CommunityToolkit/dotnet#1206 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
CommunityToolkit/dotnet#648 ·
-
feature request :mailbox_with_mail:
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
CommunityToolkit/dotnet#1214 ·
-
bug :bug:
Difficoltà 4/5 3-5 giorni Idoneità per principianti 58/100
CommunityToolkit/dotnet#1208 ·
Tutte le issue di CommunityToolkit/dotnet
Issue simili
-
go 🏃 testing 🧪
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
valkey-io/valkey-glide#7239 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
SubtitleEdit/subtitleedit#15462 ·
I maintainer di solito rispondono entro 1 giorno
-
:watch: Not Triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
comp:instrumentation.aspnetcore
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
open-telemetry/opentelemetry-dotnet-contrib#5427 ·
I maintainer di solito rispondono entro 1 giorno
-
[feature request] Condier making `TelemetrySpan`'s constructor and `Activity` property publicApertaenhancement needs-triage pkg:OpenTelemetry
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
open-telemetry/opentelemetry-dotnet#7851 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno