如何将 ExpandoObject 从 C# 传递到 IronRuby?

发布于 2024-08-23 07:52:53 字数 713 浏览 12 评论 0原文

执行下面的代码在最后一行给出以下异常:

InvalidOperationException: "unbound variable: value"

var rubyRuntime = Ruby.CreateRuntime();
rubyRuntime.UseFile("HandleMoveRequested.rb");
var engine = rubyRuntime.GetEngine("rb");
dynamic ruby = engine.Runtime.Globals;

var handler = ruby.HandleMoveRequested.@new();

dynamic msg = new ExpandoObject();
msg.x = 1;
msg.y = 2;

handler.handle(msg);

HandleMoveRequested.rb 的内容是:

class HandleMoveRequested
    def handle(msg)
        System::Console.WriteLine msg.x
        System::Console.WriteLine msg.y
    end
end

基本上我只是希望能够传递一个完全动态的对象进入该 Ruby 对象的“handle”方法,并使其能够访问该对象上的“x”和“y”属性。我是不是找错了树?

Executing the below code gives me the following exception on the last line:

InvalidOperationException: "unbound variable: value"

var rubyRuntime = Ruby.CreateRuntime();
rubyRuntime.UseFile("HandleMoveRequested.rb");
var engine = rubyRuntime.GetEngine("rb");
dynamic ruby = engine.Runtime.Globals;

var handler = ruby.HandleMoveRequested.@new();

dynamic msg = new ExpandoObject();
msg.x = 1;
msg.y = 2;

handler.handle(msg);

The contents of HandleMoveRequested.rb are:

class HandleMoveRequested
    def handle(msg)
        System::Console.WriteLine msg.x
        System::Console.WriteLine msg.y
    end
end

Basically I just want to be able to pass a fully dynamic object into that Ruby object's "handle" method and have it be able to access the "x" and "y" properties on that object. Am I barking up the wrong tree?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还在原地等你 2024-08-30 07:52:53

在从源代码构建最新版本后,我测试了您的代码(按原样):
http://github.com/ironruby/ironruby

请尝试一下。我想该修复将包含在下一个 RC 版本(RC3?)及更高版本中。
当您从源代码构建时,确保使用 Ruby4.sln 构建“V4 Release”版本

编辑:我自己测试过,这在最新版本中没有问题

I tested your code (as-is) after building the latest from source:
http://github.com/ironruby/ironruby

Please try this. I'd imagine the fix will be included in the next RC Build (RC3?) and later.
When you build from source, make sure you build the "V4 Release" build using Ruby4.sln

Edit: Tested myself, this works without issue in latest

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文