dotnet
dotnet copied to clipboard
`[RelayCommand]` does not work with default/optional arguments as the command parameter
Describe the bug
The following command compiles, but causes a runtime error when called.
public override async Task SomeCommandAsync(bool optional = false, CancellationToken cancellationToken = default)
{
}
The same command without the first optional argument does work, i.e. the optional CancellationToken is handled correctly, as far as I can tell.
If it isn't possible to dispatch the command with that default/optional argument, then the analyzer should probably produce a compiler error notifying the user that RelayCommands cannot have optional arguments.
Regression
No response
Steps to reproduce
- Paste the code above into a class inside a project that references the CommunityToolkit
- Run the application
Expected behavior
Either pass in the provided value or the default or generate a compiler error to notify the user that commands cannot have optional arguments.
Screenshots
No response
IDE and version
VS 2022
IDE version
No response
Nuget packages
- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [x] CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
CommunityToolkit.Mvvm 8.4.0
Additional context
No response
Help us help you
No, just wanted to report this