# Getting the .NET type of an IronRuby class

**URL:** <https://www.ruby-forum.com/t/getting-the-net-type-of-an-ironruby-class/128640>\
**Category:** IronRuby\
**Created:** [February 9, 2008, 7:42pm UTC](https://www.ruby-forum.com/t/getting-the-net-type-of-an-ironruby-class/128640 "2008-02-09T19:42:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dermothogan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dermothogan](https://www.ruby-forum.com/u/dermothogan)\
**Post date:** [February 9, 2008, 7:42pm UTC](https://www.ruby-forum.com/t/getting-the-net-type-of-an-ironruby-class/128640/1 "2008-02-09T19:42:40Z")

</div>

Is there a simple way of getting the .NET type of an IronRuby class?

I have this code:

resources =  
System::ComponentModel::ComponentResourceManager.new(X.class)

where X is a class. But this doesn’t do it - I get a run time exception.

Any ideas?

Dermot

---

<div class="post-metadata">

**Author:** ![dermothogan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dermothogan](https://www.ruby-forum.com/u/dermothogan)\
**Post date:** [February 9, 2008, 9:09pm UTC](https://www.ruby-forum.com/t/getting-the-net-type-of-an-ironruby-class/128640/2 "2008-02-09T21:09:50Z")

</div>

Michael L. wrote:

> resources = System::ComponentModel::ComponentResoruceManager.new(  
> X.GetType)

Thanks! Yes, it’s obvious: I think I’ve got trouble switching beteen  
thinking in Ruby and thinking in .NET …

Dermot

---

<div class="post-metadata">

**Author:** ![dermothogan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dermothogan](https://www.ruby-forum.com/u/dermothogan)\
**Post date:** [February 9, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/getting-the-net-type-of-an-ironruby-class/128640/3 "2008-02-09T20:10:20Z")

</div>

resources = System::ComponentModel::ComponentResoruceManager.new(  
X.GetType)

or if you’d rather:

require ‘mscorlib’

def typeof(object)  
System::Type.GetTypeFromHandle(System::Type.GetTypeHandle(object))  
end

On Feb 9, 2008 1:42 PM, Dermot H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Any ideas?
> 
> ## Dermot
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Ironruby-core mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
Michael L.  
[Polymath Programmer]  
[http://michaeldotnet.blogspot.com](http://michaeldotnet.blogspot.com)

---

<div class="post-metadata">

**Author:** ![dermothogan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dermothogan](https://www.ruby-forum.com/u/dermothogan)\
**Post date:** [February 11, 2008, 3:19pm UTC](https://www.ruby-forum.com/t/getting-the-net-type-of-an-ironruby-class/128640/4 "2008-02-11T15:19:13Z")

</div>

We are evaluating IronRuby and/or IronPython to use as event handling  
script language in a WPF / XAML GUI project.

Our current XAML / C# design has the regular VS2008 -generated logic of  
creating custom class (and enbedded BAML) for each XAML-file. We also  
use heavily custom controls to build up larger panels / windows:

MyControl.xaml:

...

Window1.xaml:

 ... ... ... ...

While I have been able to attach event handlers defined in IronPython  
2.0 to the various GUI classes, I would find it more natural if I could  
derive classes in Ruby from the corresponding CLR-classes:

class MyControlRuby \< MyControl

def Clicked(sender, args)  
…  
end

However, I suspect that re-using such classes on the XAML-side would not  
work:

 ... ... ... ...

Can someone confirm or deny my assumption about XAML being  
not-so-DLR-language-friendly here as I suppose?

Might this approach have better changes of success if I would use  
IronPython 1.1 that can supposedly compile Python classes to CLR  
classes?

Robert B.  
Software architect  
Napa Ltd  
Tammasaarenkatu 3, Helsinki FI-00180  
P.O.Box 470, Helsinki FI-00181

Tel. +358 9 22 813 1  
Direct. +358 9 22 813 611  
GSM +358 45 11 456 02  
Fax. +358 9 22 813 800

Email: removed\_email\_address@domain.invalid

> **[Home – NAPA](https://www.napa.fi/)**
>
> NAPA provides intelligent solutions for maritime industry: Software, Services and Data Analysis for Ship Design and Operation. We combine naval architecture, shipping and digital expertise to help maritime business make the decisions that matter.
