Forum: IronRuby Getting property list from both Ruby and .Net objects

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Aa3f022fbab4e16049eded7e2351f270?d=identicon&s=25 Alexander R. (strider_ajr)
on 2012-09-24 10:21

I need some tools to get property names of both Ruby objects and .Net
objects. First I thought that there'll be no problem with it. I tried to
do it like:

def GetPropertyList(obj)
  return obj.instance_variables

But it turned out that when "obj" is a .Net object
obj.instance_variables returns nothing. Well, it returns an array but
array is empty.

For example:

require "Foo"
include FooModule

foo =
foo.NetVal1 = "Hello"
foo.NetVal2 = 100

puts foo.class # => FooModule::Foo
puts foo.NetVal1 # => Hello
puts doo.NetVal2 # => 100

puts foo.instance_variables # =>             #it's blank here
puts foo.instance_variables.class # => Array

Well, then I thought that I can use reflection to get property list for
.Net objects:

def GetPropertyList(obj)
  array =
  obj.GetType().GetProperties.each do |prop|

But it didn't work for a ruby object. I tried to somehow find out
weather object is from ruby or .Net and depending on it parse objects,
but I couldn't think of any working solution.

So my question is:
Give me a hint on how I can parse both ruby and .net objects using one

Thanks in advance,
Ccabb5c41e9b0160079a9aef6bd30ff0?d=identicon&s=25 Eduardo B. (eblumenfeld)
on 2012-09-27 20:12
Hi Alex:



it will give you the list of all the methods available

(From the point of view of IronRuby, a .net object shows the methods

you would find

two methods for, one for set another for get of a variable,

for example, saying that you have a propety of the object called "name"  (would return the actual setting for the variable (get) ) = "test".to_clr_string (would set the name in the .net object)

   .to_clr_string is important to convert the ruby string object to the
corresponding clr object (System::String)


Ccabb5c41e9b0160079a9aef6bd30ff0?d=identicon&s=25 Eduardo B. (eblumenfeld)
on 2012-09-27 20:17
A quick way of finding all the properties that you can set of a .net
object would be:


(filter by all the properties that you can set)
This topic is locked and can not be replied to.