Geeks With Blogs
Josh Reuben
            Func<bool> a = ()=>true;
            Func<string> b = () => string.Empty;
            Func<string[], string> c = (words) => words.Aggregate((current, next) => current + " " + next); 
 
           var dels = new Delegate[] {a,b,c};
           var x = dels[0].DynamicInvoke();
           var y = dels[1].DynamicInvoke();
           var z = dels[2].DynamicInvoke(new[] {new[] { "The""Cat""in""the""Hat" }});
Posted on Sunday, January 23, 2011 10:47 AM | Back to top


Comments on this post: The power of DynamicInvoke !

# re: The power of DynamicInvoke !
Requesting Gravatar...
Hmm... ein paar Worte dazu wären nicht schlecht. Jemand der noch nie DynamicInvoke benutzt hat, weiß nicht was da passiert und was der Sinn dahinter ist.
Left by Rainer Hilmer on Jan 23, 2011 2:25 PM

# re: The power of DynamicInvoke !
Requesting Gravatar...
A few words for an explanation would be appropriate. Someone who never used DynamicInvoke does not know what's happening here and what's it all good for.
Left by Rainer Hilmer on Jan 23, 2011 2:30 PM

# re: The power of DynamicInvoke !
Requesting Gravatar...
I would say that such a short snippet is self evident - you can store and invoke multiple delegates with different generic signatures and invoke them dynamically (ala late binding) by supplying a params array of inputs that match the method signature.

cheers,
Josh
Left by Josh Reuben on Jan 23, 2011 4:50 PM

# re: The power of DynamicInvoke !
Requesting Gravatar...
Thank you ! You helped me to solve a very big problem here !
Left by Felipe C. Gehrke on Mar 12, 2012 10:34 PM

# re: The power of DynamicInvoke !
Requesting Gravatar...
It is great to know this idea. I might as well be using this information. - Antiquities of California
Left by James Washington on Dec 29, 2016 4:54 AM

Your comment:
 (will show your gravatar)


Copyright © JoshReuben | Powered by: GeeksWithBlogs.net