# Code Review: ClrMembers

**URL:** <https://www.ruby-forum.com/t/code-review-clrmembers/169231>\
**Category:** IronRuby\
**Created:** [June 1, 2009, 7:07am UTC](https://www.ruby-forum.com/t/code-review-clrmembers/169231 "2009-06-01T07:07:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [June 1, 2009, 7:07am UTC](https://www.ruby-forum.com/t/code-review-clrmembers/169231/1 "2009-06-01T07:07:18Z")

</div>

tfpt review “/shelveset:ClrMembers;REDMOND\tomat”

Adds the following methods to improve CLR interop:

- 

```
     Kernel#clr_member

```

Returns RubyMethod that represents one or more CLR members (a field, an  
event, a method, a group of overloaded methods, a property, an indexer,  
an operator, etc.). Unlike Kernel#methods clr\_member ignores Ruby  
methods, undefined and removed methods. So even if a CLR is redefined by  
a Ruby method definition clr\_member will return it. It also ignores Ruby  
inheritance hierarchy and returns members from all CLR super-types. For  
example:

> > > Array.ancestors

=\> [Array, Enumerable, Object, Kernel]

> > > Array.to\_clr\_type.base\_type

=\> System.Collections.Generic.List`1[System.Object]

> > > [].method(:get\_enumerator)

undefined method `get_enumerator' for class`Array’ (NameError)

> > > [].clr\_member(:get\_enumerator)

=\> #\<Method: Array#get\_enumerator\>

> > > [].clr\_member(:get\_enumerator).call

=\> System.Collections.Generic.List`1+Enumerator[System.Object]

clr\_member can’t be used on a Ruby class:

> > > class C; new; end.clr\_member(:p)

`C’ doesn’t represent a CLR type (TypeError)

- 

```
     Class#clr_ctor/clr_constructor

```

Similar to clr\_member. Returns a group of CLR constructors for given  
class that represents a CLR type. A call to the resulting group will  
return a new instance of the type. As with any method group, “overloads”  
method could be used to select a particular overload. Examples:

> > > puts Thread.clr\_ctor.clr\_members  
> > > Void .ctor(System.Threading.ThreadStart)  
> > > Void .ctor(System.Threading.ThreadStart, Int32)  
> > > Void .ctor(System.Threading.ParameterizedThreadStart)  
> > > Void .ctor(System.Threading.ParameterizedThreadStart, Int32)  
> > > =\> nil
> 
> > > puts Thread.clr\_ctor.overloads(System::Threading::ThreadStart).clr\_members  
> > > Void .ctor(System.Threading.ThreadStart)  
> > > =\> nil
> 
> > > Thread.clr\_ctor.overloads(System::Threading::ThreadStart).call(lambda { puts ‘hello’ })  
> > > =\> #\<Thread:0x000005c unstarted\>

- 

```
     Class#clr_new

```

Creates an instance of the class using CLR constructors.

Splits RubyMethodGroupInfo into 2 classes: RubyOverloadGroupInfo \<:  
RubyMethodGroupInfo. The former participates in overload inheritance: it  
comprises of overloads whose declaring types might differ and which  
could be hidden by Ruby method definitions. More bookkeeping is needed  
to support this. The latter is a simple group that groups arbitrary  
methods and is created by selecting and grouping bunch of CLR methods  
(e.g. using “overloads”, “of”, “clr\_member”, “clr\_ctor” methods).

Tomas

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [June 1, 2009, 7:38pm UTC](https://www.ruby-forum.com/t/code-review-clrmembers/169231/2 "2009-06-01T19:38:49Z")

</div>

Looks good, other than that ModuleOps.cs doesn’t appear to have any  
changes in it =P  
~js

From: Tomas M.  
Sent: Sunday, May 31, 2009 10:06 PM  
To: IronRuby External Code R.  
Cc: removed\_email\_address@domain.invalid  
Subject: Code Review: ClrMembers

tfpt review “/shelveset:ClrMembers;REDMOND\tomat”

Adds the following methods to improve CLR interop:

- 

```
     Kernel#clr_member

```

Returns RubyMethod that represents one or more CLR members (a field, an  
event, a method, a group of overloaded methods, a property, an indexer,  
an operator, etc.). Unlike Kernel#methods clr\_member ignores Ruby  
methods, undefined and removed methods. So even if a CLR is redefined by  
a Ruby method definition clr\_member will return it. It also ignores Ruby  
inheritance hierarchy and returns members from all CLR super-types. For  
example:

> > > Array.ancestors

=\> [Array, Enumerable, Object, Kernel]

> > > Array.to\_clr\_type.base\_type

=\> System.Collections.Generic.List`1[System.Object]

> > > [].method(:get\_enumerator)

undefined method `get_enumerator' for class`Array’ (NameError)

> > > [].clr\_member(:get\_enumerator)

=\> #\<Method: Array#get\_enumerator\>

> > > [].clr\_member(:get\_enumerator).call

=\> System.Collections.Generic.List`1+Enumerator[System.Object]

clr\_member can’t be used on a Ruby class:

> > > class C; new; end.clr\_member(:p)

`C’ doesn’t represent a CLR type (TypeError)

- 

```
     Class#clr_ctor/clr_constructor

```

Similar to clr\_member. Returns a group of CLR constructors for given  
class that represents a CLR type. A call to the resulting group will  
return a new instance of the type. As with any method group, “overloads”  
method could be used to select a particular overload. Examples:

> > > puts Thread.clr\_ctor.clr\_members  
> > > Void .ctor(System.Threading.ThreadStart)  
> > > Void .ctor(System.Threading.ThreadStart, Int32)  
> > > Void .ctor(System.Threading.ParameterizedThreadStart)  
> > > Void .ctor(System.Threading.ParameterizedThreadStart, Int32)  
> > > =\> nil
> 
> > > puts Thread.clr\_ctor.overloads(System::Threading::ThreadStart).clr\_members  
> > > Void .ctor(System.Threading.ThreadStart)  
> > > =\> nil
> 
> > > Thread.clr\_ctor.overloads(System::Threading::ThreadStart).call(lambda { puts ‘hello’ })  
> > > =\> #\<Thread:0x000005c unstarted\>

- 

```
     Class#clr_new

```

Creates an instance of the class using CLR constructors.

Splits RubyMethodGroupInfo into 2 classes: RubyOverloadGroupInfo \<:  
RubyMethodGroupInfo. The former participates in overload inheritance: it  
comprises of overloads whose declaring types might differ and which  
could be hidden by Ruby method definitions. More bookkeeping is needed  
to support this. The latter is a simple group that groups arbitrary  
methods and is created by selecting and grouping bunch of CLR methods  
(e.g. using “overloads”, “of”, “clr\_member”, “clr\_ctor” methods).

Tomas
