在 IronRuby 中使用重载构造函数实例化对象时出现问题?
我有 c# 类“Document”,带有重载构造函数 (int id)、(guid id) 和一些更多参数选项 - 并且没有 0 个参数的重载。当我尝试使用 IronRuby 创建新对象时,我绊倒了。它说它想要有 0 个参数,所以:
d = Document.new
工作正常。但是当我尝试时
d = Document.new some_integer
,我收到错误消息
"wrong number of arguments (1 for 0)"
The class def 看起来像这样:
public Document(int id) : base(id)
{
// some code
}
编辑:这是完整的代码。它位于 Umbraco 上下文中,我将命名空间转换为小写,以便能够在 IronRuby 中使用它们:
$LOAD_PATH << "C:\\inetpub-dev\\dev.mysite.com\\bin"
require "cms.dll"
require "businesslogic.dll"
Web = Object.const_get("umbraco").const_get("cms").const_get("businesslogic").const_get("web")
existing_document_id = 1065
existing_document = Web::Document.new(existing_document_id)
C# 中的相同代码:
var existingDocument = new umbraco.cms.businesslogic.web.Document(1065);
I have a c# class "Document" with overloaded constructors (int id), (guid id) and some more parameter options - and no overload with 0 parameters. When I try to create a new object with IronRuby I stumble. It says it wants to have 0 arguments, so:
d = Document.new
works fine. But when I try
d = Document.new some_integer
I get the error message
"wrong number of arguments (1 for 0)"
The class def looks like this:
public Document(int id) : base(id)
{
// some code
}
Edit: here's the complete code. It's in an Umbraco context, and I translate namespaces with lower caseing to be able to use them in IronRuby:
$LOAD_PATH << "C:\\inetpub-dev\\dev.mysite.com\\bin"
require "cms.dll"
require "businesslogic.dll"
Web = Object.const_get("umbraco").const_get("cms").const_get("businesslogic").const_get("web")
existing_document_id = 1065
existing_document = Web::Document.new(existing_document_id)
Same code in C#:
var existingDocument = new umbraco.cms.businesslogic.web.Document(1065);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想知道您是否在某个地方遇到了命名空间冲突。
Document 是否有可能在您所包含的内容中的其他地方定义?
我们看不到您的基类是什么样子
另外,我们看不到您正在使用的要求/包含内容
我设置了一个示例,它似乎按预期工作:
以下是会话的样子(使用 IronRuby 1.1.4.0):
您能否尝试使用这个更简单的示例代码,看看是否可以按照您期望的方式创建对象?
I wonder if you are hitting a namespace collision somewhere.
Is there any possibility that Document is defined somewhere else in what you are including?
We can't see what your base class looks like
Also, we can't see what requires/includes you are using
I set up an example, and it seems to work as expected:
Here is what the session looked like (using IronRuby 1.1.4.0):
Could you try with this simpler example code and see if you can create the objects in the way you are expecting?