ReactiveUI icon indicating copy to clipboard operation
ReactiveUI copied to clipboard

Add type-safe InvokeCommandSafe without ICommand overloads.

Open HavenDV opened this issue 3 years ago • 2 comments

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

HavenDV avatar Jul 27 '21 13:07 HavenDV

Or do it more radically and add a separate name for the ICommand overloads to avoid documentation problems.

HavenDV avatar Jul 27 '21 13:07 HavenDV

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))

HavenDV avatar Jul 27 '21 18:07 HavenDV