-
Notifications
You must be signed in to change notification settings - Fork 395
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
Conversation
src/System.CommandLine/Command.cs
Outdated
/// <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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IValueDescriptor<T>
andBinderBase<T>
Makes progress towards #2071
contributes to #1918
fixes #2000, fixes #1878 (there will only be one handler)