# Difficulties grasping generics + IronRuby - any idea? (OpenXML)

**URL:** <https://www.ruby-forum.com/t/difficulties-grasping-generics-ironruby-any-idea-openxml/179262>\
**Category:** IronRuby\
**Created:** [November 20, 2009, 4:23pm UTC](https://www.ruby-forum.com/t/difficulties-grasping-generics-ironruby-any-idea-openxml/179262 "2009-11-20T16:23:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [November 20, 2009, 4:23pm UTC](https://www.ruby-forum.com/t/difficulties-grasping-generics-ironruby-any-idea-openxml/179262/1 "2009-11-20T16:23:19Z")

</div>

Hi,

I’m testing out the OpenXML SDK with IronRuby (0.9.2). Turns out it’s  
full  
of generics in there, a good play field.

Here I’m trying to use the API to retrieve a list of sheets in an  
existing  
xslx.

I’m having a hard-time understanding why I can’t call “b.first” in the  
next  
snippet (full version at [generics-ironruby.rb · GitHub](http://gist.github.com/239555)):

doc = SpreadsheetDocument.open(‘docs/single-cell.xlsx’, false)

a = doc.workbook\_part.workbook.method(:get\_first\_child).of(Sheets).call  
puts a

# → DocumentFormat.OpenXml.Spreadsheet.Sheets

b = a.method(:elements).of(Sheet).call  
puts b

# →

DocumentFormat.OpenXml.OpenXmlElementList+d\_\_0`1[DocumentFormat.OpenXml.Spreadsheet.Sheet]

# b.first or anything similar fails

- 
- 

It turns out that b.methods shows a “to\_a” method is available, then I  
can  
do :

puts b.to\_a.first # woot!

# → DocumentFormat.OpenXml.Spreadsheet.Sheet

So my questions are:

- why can’t I call b.first ? (maybe there’s something obvious I didn’t  
see -  
I assume it’s probably that)
- are there better ways of writing this ?

And if you are interested to follow (I really need to wrap some ruby  
sugar  
around all this to make it easier to work with), I’ll push my  
experiments  
here:

> **[GitHub - thbar/openxml-labs: Experiments with OpenXML SDK](https://github.com/thbar/openxml-labs)**
>
> Experiments with OpenXML SDK . Contribute to thbar/openxml-labs development by creating an account on GitHub.

thanks,

Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [November 20, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/difficulties-grasping-generics-ironruby-any-idea-openxml/179262/2 "2009-11-20T20:09:15Z")

</div>

You can’t call a C# extension method off of the object. You might try  
creating a mixin to add a method\_missing to catch and call the  
appropriate  
extensions. Otherwise, I think you have to call them as static members,  
e.g.  
Enumerable.First.Of(Sheet).call(b). That looks horrifying, I know. I  
don’t  
have IR available on this machine, or I would try it myself. Let me know  
how  
that goes. This seems like it will be a fairly common problem for things  
like LINQ, PFx and Rx. Maybe we can come up with a simple,  
one-size-fits-all  
solution?

Ryan R.

Email: removed\_email\_address@domain.invalid  
LinkedIn: [http://www.linkedin.com/in/ryanriley](http://www.linkedin.com/in/ryanriley)  
Blog: [http://wizardsofsmart.net/](http://wizardsofsmart.net/)  
Website: [http://panesofglass.org/](http://panesofglass.org/)

On Fri, Nov 20, 2009 at 9:17 AM, Thibaut BarrÃ¨re

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [November 20, 2009, 9:55pm UTC](https://www.ruby-forum.com/t/difficulties-grasping-generics-ironruby-any-idea-openxml/179262/3 "2009-11-20T21:55:47Z")

</div>

Hi Ryan,

You can’t call a C# extension method off of the object. You might try

> creating a mixin to add a method\_missing to catch and call the appropriate  
> extensions. Otherwise, I think you have to call them as static members, e.g.  
> Enumerable.First.Of(Sheet).call(b). That looks horrifying, I know. I don’t  
> have IR available on this machine, or I would try it myself. Let me know how  
> that goes. This seems like it will be a fairly common problem for things  
> like LINQ, PFx and Rx. Maybe we can come up with a simple, one-size-fits-all  
> solution?

yikes 🙂 I was pretty sure something like that was involved.

I think I’ll try the static version first, see if it works.

thanks for the hint, I’ll keep you posted 🙂

– Thibaut
