Open
Description
Background and motivation
For abstractions like ICommand
it's useful to have a standard implementation that does nothing. We have some of them already, such as Stream.Null
and TextWriter.Null
.
API Proposal
namespace System.Windows.Input;
public partial interface ICommand
{
public static ICommand Null { get; } = new NullCommand();
private sealed class NullCommand : ICommand
{
public event EventHandler? CanExecuteChanged
{
add {}
remove {}
}
public bool CanExecute(object? parameter)
{
return true;
}
public void Execute(object? parameter)
{
// Do nothing
}
}
}
API Usage
private ICommand _command = ICommand.Null; // Might be set to something meaningful later
Alternative Designs
We could put it on a class instead, but we don't have a built-in implementation of ICommand
in System.ObjectModel.dll
, so I don't believe there is a good candidate. We could, of course, create one.
Risks
No response