Say you have a Dictionary < string,object > . It might contain decimals, strings or other valid types. It could also contain Actions and Funcs like:
Action<string> or Action<int,int,string> etc.
Is there a general way to discover that a given key k points to an Action or Func and then invoke that same value?
var value = dict[key];
//some sort of predicate checking if value is invokeable
I have considered using the dynamic keyword and simply calling Invoke( args ) on the resulting object, but this seems slow and inelegant.
You could test off it is a delegate:
However! Knowing what args to provide (in an object-array) is tricky if you don’t know the signature ahead of the invoke.