views:

203

answers:

2

Hi

How can I call a generic method (.NET 3.5 SP1) from IronRuby v0.9? Trying to do something as obj.method(:method_name).of(String).call seems not to work as "of" is an unknown method.

Thanks a lot

+1  A: 

It works for me (I'm using 0.9.1):

IronRuby:

obj = ClassLibrary1::Class1.new
obj.method(:test).of(String).call("test")

C#:

namespace ClassLibrary1
{
    public class Class1
    {
     public string Test<T>(T param)
     {
      return param.ToString();
     }
    }
}
Shay Friedman
You're right, this seems to be an issue with the v0.9 release (http://dlr.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20378).If I compile the 0.9.1 release myself, it works for me as well.
JPW
The 0.9.1 binary release is out now, so you don't need to compile it yourself
Jimmy Schementi
+2  A: 

You can also use array indexers to pass generic arguments to methods, and you can execute a proc with array indexers as well, so Shay's example can look like this too:

obj.method(:test)[String]["test"]
Jimmy Schementi
This doesn't work for me Jimmy. obj.method(:test)[String] returns a String object - 'String', so passing ["test"] to it results in an exception.
Shay Friedman