Question

How can I set a delegate on a ScriptScope under IronRuby? I tried the above code but I got an ArgumentException when calling the function.

scope.SetVariable("import", new Action<string>(DSLImport));

import "Data"

Also, how can I use the above code sending the block as a callback to C# code?

import "Data" do |f|
    f.foo = false
end

No correct solution

OTHER TIPS

I found a way that might not be the best, but works. It's a extension method to ScriptScope:

public static void SetMethod(this ScriptScope scope, string name, Delegate method)
{
    scope.SetVariable(name + "__delegate", method);
    scope.Engine.Execute("def " + name + "(*args, &block)\nargs.push block if block != nil\n" + name + "__delegate.invoke(*args)\nend", scope);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top