# Typeof?

**URL:** <https://www.ruby-forum.com/t/typeof/162125>\
**Category:** IronRuby\
**Created:** [March 5, 2009, 11:47pm UTC](https://www.ruby-forum.com/t/typeof/162125 "2009-03-05T23:47:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [March 5, 2009, 11:47pm UTC](https://www.ruby-forum.com/t/typeof/162125/1 "2009-03-05T23:47:20Z")

</div>

Having another go at some WCF stuff again.  
I have a C# method that accepts a type. I want to pass it an interface.

interface IMyInterface;  
public void DoStuff( Type t );

DoStuff( typeof(IMyInterface) );

> From the ruby side, I’m importing both IMyInterface and DoStuff from C#, I  
> just want to call the method from ruby.

When I do this:

do\_stuff( IMyInterface );

I get “can’t convert Module into System::Type”

If I try pass in a class, I get the similar “can’t convert Class into  
System::Type”

So, is there a way to get a .NET Type from a ruby object, particularly  
an  
interface/module? (it is a real .NET type as it’s loaded from a C# dll)

Any help is greatly appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [March 6, 2009, 12:34am UTC](https://www.ruby-forum.com/t/typeof/162125/2 "2009-03-06T00:34:51Z")

</div>

## IMyInterface.to\_clr\_type

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
GSM: +32.486.787.582  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)

---

<div class="post-metadata">

**Author:** ![Orion\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@Orion\_E](https://www.ruby-forum.com/u/Orion_E)\
**Post date:** [March 6, 2009, 12:35am UTC](https://www.ruby-forum.com/t/typeof/162125/3 "2009-03-06T00:35:27Z")

</div>

IMyInterface.to\_clr\_type should work.

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Orion E.  
Sent: Thursday, March 05, 2009 1:59 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Typeof ??

Having another go at some WCF stuff again.

I have a C# method that accepts a type. I want to pass it an interface.

interface IMyInterface;  
public void DoStuff( Type t );

DoStuff( typeof(IMyInterface) );

> From the ruby side, I’m importing both IMyInterface and DoStuff from C#, I just want to call the method from ruby.

When I do this:

do\_stuff( IMyInterface );

I get “can’t convert Module into System::Type”

If I try pass in a class, I get the similar “can’t convert Class into  
System::Type”

So, is there a way to get a .NET Type from a ruby object, particularly  
an interface/module? (it is a real .NET type as it’s loaded from a C#  
dll)

Any help is greatly appreciated. Thanks.
