ReactiveUI
ReactiveUI copied to clipboard
Add type-safe InvokeCommandSafe without ICommand overloads.
Now, when changing command parameters without explicitly specifying the types of arguments, the InvokeCommand (ICommand) overload is called, which ignores the input type and throws an exception only during runtime.
// this throws runtime exception
_ = Observable<Input>()
.Select(_ => OtherTypeInput)
.InvokeCommand(Command);
// this throws compile time exception
_ = Observable<Input>()
.Select(_ => OtherTypeInput)
.InvokeCommand<Input, Output>(Command);
// should throw compile time exception
_ = Observable<Input>()
.Select(_ => OtherTypeInput)
.InvokeCommandSafe(Command);
other suggested names: InvokeReactiveCommand
Or do it more radically and add a separate name for the ICommand overloads to avoid documentation problems.
A similar problem concerns the ReactiveCommand.Execute()
method, which always has a no-argument overload. When changing command parameters from Unit to something new, a runtime exception is thrown, because an overload with no arguments is called. I would consider removing the empty overload (replacing it with ReactiveCommand.Execute(Unit.Default)
), or creating a separate method to be explicitly called with arguments (ReactiveCommand.ExecuteWith(Unit.Default)
)