Replies: 1 comment 3 replies
-
Lambda expressions are target typed. In this case, the target type is the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Demand
I have an asynchronous callback delegate that I want people to use can use asynchronous lambda expressions for assignments, as well as synchronous lambda expressions for assignments. This avoids the hassle of returning a Task.CompletedTask if there is only synchronous code in the asynchronous lambda expression.
Code base
First, I wrapped an asynchronous delegate with a struct,
Then you can assign a value to the asynchronous delegate in the constructor, and at the same time overload a constructor that converts the synchronous delegate to asynchronous.
Finally, using implicit conversion, it is hoped that synchronous and asynchronous delegates can be directly converted into this struct.
The basic code is as follows:
Then when using, I declare a usage class object with the following code:
Then, you can use it like this:
But it actually failed.
Issue
Why is the following code successful?
And the direct assignment fails?
Suggestion
I think that it can be
var
from(int a) = > { }
; Inferring the action of type var means that the compiler can derive it, so why can't it be implicitly converted and assigned after derivation?This feels like a problem that can be solved, and I hope that the government will pay attention to it and solve it.
Or it would be nice if it fundamentally solved the problem that asynchronous delegates can assign synchronous methods.
Beta Was this translation helpful? Give feedback.
All reactions