Skip to content

Instantly share code, notes, and snippets.

@JamesKyburz
Created January 11, 2012 20:40
Show Gist options
  • Save JamesKyburz/1596648 to your computer and use it in GitHub Desktop.
Save JamesKyburz/1596648 to your computer and use it in GitHub Desktop.
Dynamic dispatch in c#
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