Pass an array from IronRuby to C#

Posted by cgyDeveloper on Stack Overflow See other posts from Stack Overflow or by cgyDeveloper
Published on 2010-03-19T23:25:27Z Indexed on 2010/03/19 23:31 UTC
Read the original article Hit count: 205

Filed under:
|

I'm sure this is an easy fix and I just can't find it, but here goes:

I have a C# class (let's call it Test) in an assembly (let's say SOTest.dll). Here is something along the lines of what I'm doing:

private List<string> items;

public List<string> list_items()
{
    return this.items;
}

public void set_items(List<string> new_items)
{
    this.items = new_items;
}

In the IronRuby interpreter I run:

>>> require "SOTest.dll"
true
>>> include TestNamespace
Object
>>> myClass = Test.new
TestNamespace.Test
>>> myClass.list_items()
['Apples', 'Oranges', 'Pears']
>>> myClass.set_items ['Peaches', 'Plums']
TypeError: can't convert Array into System::Collections::Generic::List(string)

I get a similar error whether I make the argument a 'List< string >', 'List< object >' or 'string[ ]'.

What is the proper syntax? I can't find a documented mapping of types anywhere (because it's likely too complicated to define in certain scenarios given what Ruby can do).

© Stack Overflow or respective owner

Related posts about ironruby

Related posts about c#