You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The signature of the lambda can easily be determined at compile-time and thus it would be possible to implicitly cast it to MethodInvoker (or have the compiler generate the required explicit cast).
The text was updated successfully, but these errors were encountered:
DavidArno
changed the title
Proposal: Implicitly cast lambdas to be cast to matching signature delegates
Proposal: Implicitly cast lambdas to matching signature delegates
Mar 7, 2016
Why would the compiler cast that delegate to MethodInvoker? The method doesn't accept a MethodInvoker, it accepts a Delegate. There is no specific delegate that it requires since it invokes the delegate dynamically. The issue is that the compiler has no idea what specific delegate to use without inference based on the target of the assignment and there is no signature equivalence of delegates in the CLR. #14
If there was an overload of Control.Invoke which accepted a MethodInvoker or Action or any specific delegate type then this would no longer be a problem.
Ha, that'll teach me not to check the signature of Invoke properly. I thought I'd found a good example of what I was after. Back to the drawing board! :)
Consider the following code example for invoking a method in the display thread for a winforms application:
Currently, this code won't compile and must be written in one of the following two ways:
The signature of the lambda can easily be determined at compile-time and thus it would be possible to implicitly cast it to
MethodInvoker
(or have the compiler generate the required explicit cast).The text was updated successfully, but these errors were encountered: