[Proposal] Async methods chaining #835
Replies: 4 comments
-
Dup #827. p.s. What's going on with all these chaining proposals nowadays? 😆 |
Beta Was this translation helpful? Give feedback.
-
@eyalsk, I like fluent syntax) I've even implemented it once in pet project with helper public class FluentChainedTask<TApiFluentClient> : DynamicObject where TApiFluentClient : BaseFluentClient
{
private readonly Task<TApiFluentClient> _task;
public FluentChainedTask(Task<TApiFluentClient> task)
{
_task = task;
}
public TaskAwaiter<TApiFluentClient> GetAwaiter()
{
return _task.GetAwaiter();
}
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
var methodInfo = typeof(TApiFluentClient).GetTypeInfo().GetDeclaredMethod(binder.Name);
if (methodInfo == null)
return base.TryInvokeMember(binder, args, out result);
result = new FluentChainedTask<TApiFluentClient>(
_task
.ContinueWith(t =>
{
try
{
return (Task<TApiFluentClient>) methodInfo.Invoke(t.Result, args);
}
catch (TargetInvocationException ex)
{
ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
}
return null;
})
.Unwrap());
return true;
}
} however without support from language I lost IntelliSense. |
Beta Was this translation helpful? Give feedback.
-
See this is the problem I have with it, you actually write code, not because you need to do it but because you like the looks of it, I don't get it. |
Beta Was this translation helpful? Give feedback.
-
@eyalsk it is the same of needing abr for await |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There is a class which methods return
Task<>
with this class as a generic parameterso we ought to write code in such way
That is why I think sugar like
will be useful.
Beta Was this translation helpful? Give feedback.
All reactions