[Bug] RelayCommand Source Generator Fails Silently for Methods Starting With ‘On'
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 68/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- C#
- Estrellas
- 3.8k
- Forks
- 400
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de CommunityToolkit/dotnet
-
bug :bug:
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
CommunityToolkit/dotnet#1206 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
CommunityToolkit/dotnet#648 ·
-
feature request :mailbox_with_mail:
Dificultad 5/5 Más de una semana Aptitud para principiantes 45/100
CommunityToolkit/dotnet#1214 ·
-
bug :bug:
Dificultad 4/5 3-5 días Aptitud para principiantes 58/100
CommunityToolkit/dotnet#1208 ·
Todos los issues de CommunityToolkit/dotnet
Issues similares
-
[Simple] NavigationBar primary commands do not render AppBarButton.Content when it is a UIElementAbiertocontrol/navigationbar kind/bug triage/untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
unoplatform/uno.toolkit.ui#1652 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
microsoft/copilot-camp#1053 ·
Los mantenedores suelen responder en 1 día
-
bug effort:S P3
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
nightscout/nocturne#1861 ·
Los mantenedores suelen responder en 1 día
-
agentic-workflows area/Docs partner/agentic-workflows
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
microsoft/fluentui-blazor#5364 ·
Los mantenedores suelen responder en 1 día