# Getting value of IronRuby object's property using reflections

**URL:** <https://www.ruby-forum.com/t/getting-value-of-ironruby-objects-property-using-reflections/206220>\
**Category:** IronRuby\
**Created:** [April 26, 2011, 4:37am UTC](https://www.ruby-forum.com/t/getting-value-of-ironruby-objects-property-using-reflections/206220 "2011-04-26T04:37:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 26, 2011, 4:37am UTC](https://www.ruby-forum.com/t/getting-value-of-ironruby-objects-property-using-reflections/206220/1 "2011-04-26T04:37:34Z")

</div>

hi All,

I’m having the ruby class of following structure. I need to gets its  
value using reflection that it need to get its value using Property  
Descriptor or PropertyInfo collection. I can get this only when I use  
the attributes. If I have the object without any attributes its  
returning the public methods of the Ruby object. I need to get the  
properties using Property Descriptor, when there is no attributes in the  
object.

Please share your Idea this is important for my project.

Thanks.  
Sri

Class Structure

class Person

```
def name
    @name
end

def name=(n)
    @name = n
end

def age
    @age
end

def age=(a)
    @age = a
end

```

end

---

<div class="post-metadata">

**Author:** ![sriyas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sriyas](https://www.ruby-forum.com/u/sriyas)\
**Post date:** [April 26, 2011, 5:27am UTC](https://www.ruby-forum.com/t/getting-value-of-ironruby-objects-property-using-reflections/206220/2 "2011-04-26T05:27:59Z")

</div>

Would this be what you need?  
[http://ironruby.codeplex.com/workitem/4920](http://ironruby.codeplex.com/workitem/4920)

Tomas

---

<div class="post-metadata">

**Author:** ![sriyas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sriyas](https://www.ruby-forum.com/u/sriyas)\
**Post date:** [April 26, 2011, 7:06am UTC](https://www.ruby-forum.com/t/getting-value-of-ironruby-objects-property-using-reflections/206220/3 "2011-04-26T07:06:45Z")

</div>

Hi Tomas,

Yes exactly the same. I need to get those methods as property in C#. Do  
you have any idea to achieve this?

Thanks,  
Sri.

---

<div class="post-metadata">

**Author:** ![sriyas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sriyas](https://www.ruby-forum.com/u/sriyas)\
**Post date:** [April 27, 2011, 11:30am UTC](https://www.ruby-forum.com/t/getting-value-of-ironruby-objects-property-using-reflections/206220/4 "2011-04-27T11:30:07Z")

</div>

Hi Jimy,

Thanks for the information. But I need to use the .Net reflection API.  
I’m trying to do something with the ruby object in my WPF control. So I  
can’t use Ruby reflection API, I can get just a Ruby object I need to  
manipulate that with the help of Reflection API.

-Sri.

---

<div class="post-metadata">

**Author:** ![sriyas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sriyas](https://www.ruby-forum.com/u/sriyas)\
**Post date:** [April 28, 2011, 4:26am UTC](https://www.ruby-forum.com/t/getting-value-of-ironruby-objects-property-using-reflections/206220/5 "2011-04-28T04:26:00Z")

</div>

Hi Sri,

What is it that you are ultimately trying to accomplish? Are you wanting  
to  
bind a control to the Ruby object?

-Charles

On Wed, Apr 27, 2011 at 4:30 AM, sridharans sivamurugan \<

---

<div class="post-metadata">

**Author:** ![sriyas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sriyas](https://www.ruby-forum.com/u/sriyas)\
**Post date:** [April 26, 2011, 5:55pm UTC](https://www.ruby-forum.com/t/getting-value-of-ironruby-objects-property-using-reflections/206220/6 "2011-04-26T17:55:07Z")

</div>

On Tue, Apr 26, 2011 at 1:06 AM, sridharans sivamurugan  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks,  
> Sri.

Sri, do you actually need to use .NET Reflection APIs? If so, then  
your Ruby class would have to inherit from an interface where the  
properties you’d want to reflect over are defined. However, I highly  
doubt that you absolutely need to use .NET’s reflection; you just want  
to find the method names available on a Ruby object, correct? Ruby  
itself has it’s own reflection capabilities built into the language  
(Persion.instance\_methods), and the DLR hosting API lets you use C# to  
access Ruby-defined entities; take a look at the methods on  
ScriptEngine.Operations to see what you need to do from C#;  
GetMemberNames might be useful to you. You could also write the  
reflection code in Ruby and pass the result back to C#:

var personMethods = engine.Execute(“Person.instance\_methods -  
Object.instance\_methods”, someScope);

~Jimmy

---

<div class="post-metadata">

**Author:** ![sriyas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sriyas](https://www.ruby-forum.com/u/sriyas)\
**Post date:** [May 4, 2011, 8:17am UTC](https://www.ruby-forum.com/t/getting-value-of-ironruby-objects-property-using-reflections/206220/7 "2011-05-04T08:17:06Z")

</div>

Hi Charles,

I’m trying to get the value of the Iron Ruby objects using  
reflection(using Property Descriptor). This is my ultimate need.

-Sri.
