c# - Convert Func to Delegate -
this question has answer here:
- cast delegate func in c# 7 answers
i have following delegate defined:
public delegate object mydelegate(dynamic target);
and have func<dynamic, object>
object:
func<dynamic, object> myfunc
how can convert myfunc
mydelegate
?
i have tried these instructions, none of them worked:
mydelegate mydeleg = myfunc; mydelegate mydeleg = (mydelegate) myfunc; mydelegate mydeleg = myfunc mydelegate;
you can wrap existing delegate:
(mydelegate)(x => myfunc(x))
or equivalently:
mydelegate mydeleg = x => myfunc(x);
this causes small performance loss on each invocation code simple.
Comments
Post a Comment