Created
January 11, 2012 20:40
-
-
Save JamesKyburz/1596648 to your computer and use it in GitHub Desktop.
Dynamic dispatch in c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static ScriptEngine engine = Ruby.CreateRuntime().GetRubyEngine(); | |
static dynamic dispatcher = null; | |
public static dynamic DynamicDispatcher(this object Source) | |
{ | |
dispatcher = dispatcher ?? engine.Execute("->(o){->(*args, &block){o.send(args.shift(), *args, &block)}}"); | |
return dispatcher(Source); | |
} | |
// example command.DynamicDispatcher("Caller=", new Caller("blah..")); | |
// where Caller is an instance property of command | |
// works with Func and Action also (Ruby's &block) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment