【问题标题】:IronRuby - Wrong number of argumentsIronRuby - 参数数量错误
【发布时间】:2016-10-26 20:42:11
【问题描述】:

我刚开始使用 IronRuby。这是我的测试课:

class Program
    {
        static void Main(string[] args)
        {
            var path = @"C:\Users\frays\Desktop\test.rb";
            var engine = Ruby.CreateEngine();
            var scope = engine.Runtime.CreateScope();

            scope.SetVariable("sendNext", new Action<string>(SendNext));

            engine.ExecuteFile(path, scope);

            Console.Read();
        }

        private static void SendNext(string text)
        {
            Console.WriteLine(text);
        }
    }

这是我的测试脚本:

sendNext 'heyyy'

但是,当尝试运行程序时,它会抛出一个异常 wrong number of arguments (1 for 0),即使该方法肯定将字符串作为参数。

【问题讨论】:

    标签: ironruby


    【解决方案1】:

    这表示Calling IronRuby from C# with a delegate 是不可能的,但你可以调用invoke 方法。

    sendNext.Invoke( 'heyyy')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多