views:

276

answers:

1

Hi, :)

How can I invoke overloaded generic method in IronRuby?

I have a .net class with the following methods. (Take note that the methods are static)

Factory.cs
----
public static T CreateService<T>()
public static T CreateService<T>(string serviceName)

ironruby_sample.rb
----
service = Factory.create_service[ISomeService]

=> produces error "wrong arguments"

BTW, I'm using IronRuby 0.5. :)

Thanks a lot.

+3  A: 
Factory.method(:create_service).of(System::String).call(serviceName)

You don't have to specify the argument IronRuby will select the overload automatically. You have to grab the method and then give it (a) type parameter(s). Next you pass the arguments to the call method

Casual Jim
Thanks. . . still getting to know how IronRuby is treating c# interfaces, but I get a different error now :).
Marc Vitalis
IronRuby views interfaces as modules. so you include them in your class but to implement them you have to implement (albeit empty) the other methods on the interface too. They all have to be snake cased, according to Ruby conventions so ToString() becomes to_string
Casual Jim