Calling IronRuby from C# with a delegate

后端 未结 2 1084
囚心锁ツ
囚心锁ツ 2021-01-03 05:29

Is it possible to call an IronRuby method from C# with a delegate as parameter in such a way that yield would work?

The following gives me a wrong n

相关标签:
2条回答
  • 2021-01-03 06:15

    I'm sure Ruby's block is not a c# delegate.
    If you pass delegate to Ruby you should invoke it via delegate's Invoke method.
    Here is sample code:

    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<string>(Console.WriteLine));
    

    Can we convert c# delegate into ruby block... I don't know.

    0 讨论(0)
  • 2021-01-03 06:28

    Got an answer by IronRuby core team member Tomáš Matoušek on the IronRuby-core list that it's not possible. Yet.

    0 讨论(0)
提交回复
热议问题