使用委托从C#调用IronRuby

是否可以使用委托作为参数从C#调用IronRuby方法,以便yield可以工作?

以下给出了错误数量的参数(1表示0)exception。

 Action action = Console.WriteLine; var runtime = Ruby.CreateRuntime(); var engine = runtime.GetEngine("rb"); engine.Execute(@" class YieldTest def test yield 'From IronRuby' end end "); object test = engine.Runtime.Globals.GetVariable("YieldTest"); dynamic t = engine.Operations.CreateInstance(test); t.test(action); 

我确定Ruby的块不是ac#delegate。
如果将委托传递给Ruby,则应通过委托的Invoke方法调用它。
这是示例代码:

 var rt = Ruby.CreateRuntime(); var eng = rt.GetEngine("rb"); eng.Execute(@" class Blocktest def test(block) block.Invoke('HELLO From IronRuby') end end "); dynamic ruby = eng.Runtime.Globals; dynamic t = ruby.Blocktest.@new(); t.test(new Action(Console.WriteLine)); 

我们可以将c#delegate转换为ruby块吗…我不知道。

IronRuby核心团队成员TomášMatoušek在IronRuby核心列表上得到了答案,这是不可能的。 然而。