Skip to content

Remove set handler overloads #2089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2023

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Mar 13, 2023

  1. Remove set handler overloads to avoid confusion amongst users. We are aiming for having only one overload for sync and one for async handler.
  2. merge Command.SetHandler extension methods into Command (discoverability, BCL guidelines)
  3. remove IValueDescriptor<T> and BinderBase<T>

Makes progress towards #2071
contributes to #1918
fixes #2000, fixes #1878 (there will only be one handler)

@adamsitnik adamsitnik requested a review from jonsequitur March 13, 2023 15:20
Comment on lines 263 to 267
/// <summary>
/// Sets a command's handler based on a <see cref="Func{Task,InvocationContext}"/>.
/// </summary>
public void SetHandler(Func<InvocationContext, CancellationToken, Task> handle)
=> Handler = new AnonymousCommandHandler(handle);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way AnonymousCommandHandler checks whether the delegate returned a Task<int> rather than just a Task is rather surprising. If that feature is going to be preserved, it should be documented here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, the reference to Func{InvocationContext, Task} is not correct as there is a CancellationToken as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway the compiler is going to translate the cref to just "T:System.Func`2" so it isn't that useful to specify the type arguments in the cref. It would be more useful to state that it's for an async function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that feature is going to be preserved, it should be documented here.

Our goal is to remove InvocationContext and have an int-returning delegate that accepts a ParseResult and CancellationToken (in case of the async handler)

Besides, the reference to Func{InvocationContext, Task} is not correct as there is a CancellationToken as well.

Good point, I've updated the comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way AnonymousCommandHandler checks whether the delegate returned a Task rather than just a Task is rather surprising.

This was in place to support some of the reflection-based approaches that had been in approach in beta1 and should no longer be needed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does #2071 cover the removal of the Task<int> type check or should I file a separate issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does #2071 cover the removal of the Task type check or should I file a separate issue?

I've sent a PR that makes it mandatory for all the handlers to return an integer:

#2092

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More overloads for SetHandler (9, 10 and more args) Cannot use more than 8 options on one command
3 participants