.Net<->IR Object Mapping


#1

Hi,

Is there a table somewhere defining how .Net objects are mapped to Ruby
objects?

Thanks,
Shay


http://www.ironshay.com
Follow me: http://twitter.com/ironshay


#2

http://ironruby.net/Documentation/.NET/Names
http://ironruby.net/Documentation/.NET

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)


#3

I meant more like namespaces turn to modules, interfaces to modules,
enums to…? constants to…?

I’ll check it out now and write the results here.

Thanks for the reply!
Shay.


http://www.ironshay.com
Follow me: http://twitter.com/ironshay


#4

http://ironruby.net/Documentation/.NET/QA_Plan

There is a table there that covers most of these. Let me know if you
need something that isn’t listed.

JD

…there is no try


#5

Private method will map to a instance method, but only with
-X:PrivateBindings. Otherwise that looks great. Could I talk you into
updating the table and adding specs to
Merlin\Main\Languages\Ruby\Tests\Interop\net? Even just adding them to
uncategorized_spec.rb will work, I’ll move them around.

Thanks,

JD

…there is no try


#6

Sure. Just give me a few days.

I’ll let you know when it’s done.

Shay.

http://www.ironshay.com
Follow me: http://twitter.com/ironshay


#7

Thanks!

JD

…there is no try


#8

With a build from the latest sources, the Cucumber C# example from
http://wiki.github.com/aslakhellesoy/cucumber/ironruby-and-net is
working. Also, only two of the Cucumber tests fail. One seems to be a
test issue, and the other is because of
http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=22984.
Please try out Cucumber and let us know what your experience is.

One usability issue is that Cucumber uses the win32console gem to
color-code the results it prints to the console, so that failures are in
red, etc. However, the win32console is a native gem and does not work
with IronRuby, and so you do not get colored output. It should be quite
easy to implement the win32console library in pure Ruby code (but marked
with platform=“ironruby” as mentioned at
http://ironruby.net/Documentation/Real_Ruby_Applications/RubyGems) using
the System.Console functionality. Anyone interested in doing this?

Shri


#9

2009/6/9 Shri B. removed_email_address@domain.invalid:

With a build from the latest sources, the Cucumber C# example from http://wiki.github.com/aslakhellesoy/cucumber/ironruby-and-net is working. Also, only two of the Cucumber tests fail. One seems to be a test issue, and the other is because of http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=22984. Please try out Cucumber and let us know what your experience is.

Why is the issue filed on IronPython?


#10

The list on this page is great but it is not complete.

Here is what I came up with. Correct me if I’m mistaken:

.Net Object Ruby Object

Namespace Module
Interface Module
Class Class
Enum Class
Enum constant Class method
Constant Class method
Static method Class method
Property Getter and setter methods
Public method Instance method
Protected method Instance method
Private method Isn’t mapped at all
Delegate Class

I have to say that the delegate mapping is awesome!!!
I can’t say why, but using it with a code block is much more fun than
writing anonymous methods or lambda expressions in C# :slight_smile:

Thanks,
Shay.


http://www.ironshay.com
Follow me: http://twitter.com/ironshay


#11

That’s called dynamic language interop - Dino’s fixing bugs in IronRuby
:))

I’ve filled it under IronRuby:
http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1535

Tomas


#12

My mistake :slight_smile: It was not intentional.


#13

It also seems like protected methods and internal classes are accessible
in IR just like they were public. Is it the correct behavior?

Thanks,
Shay.


http://www.ironshay.com
Follow me: http://twitter.com/ironshay


#14

My mistake - internal classes are accessible only with
-X:PrivateBinding. Protected methods are always accessible like public
methods.


http://www.ironshay.com
Follow me: http://twitter.com/ironshay


#15

By the way, even with “-X:PrivateBinding” I can’t access private
members. Should it be done in a special way?

Thanks,
Shay.


http://www.ironshay.com
Follow me: http://twitter.com/ironshay


#16

Could you give an example where it doesn’t work?

Tomas


#17

They are only accessible if called with a receiver that is an instance
of a derived class.
Or do you observe another behavior?

Tomas


#18

I assumed a reflection like behavior… For example, doing something
like:
klass.method(:MyPrivateClrMethod).call

Can you write a simple example of what you’ve described?

Thanks,
Shay.


http://www.ironshay.com
Follow me: http://twitter.com/ironshay


#19

I can’t get it to work… What am I doing wrong?

This is my C# code:
namespace IRTests
{
public class IRTest
{
private void MyMethod() {
Console.WriteLine(“Hi from C#”);
}
}
}

And this is the IR console:

t = IRTests::IRTest.new
=> IRTests.IRTest

t.my_method
:0: undefined method `my_method’ for IRTests.IRTest:IRTests::IRTest
(NoMethodError)

t.method(:my_method)
D:\IronRuby\GitRepository\ironruby\Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTED\Builtins\KernelOps.cs:1437:in
method': undefined methodmy_method’ for class `IRTests::IRTest’
(NameError) from :0

Thanks!
Shay.

Shay F.
http://www.ironshay.com
Follow me: http://twitter.com/ironshay


#20

Works just fine for me. How are you starting up the console? Here’s my
method:
[201] > ir -X:PrivateBinding
IronRuby 0.5.0.0 on .NET 2.0.50727.4918
Copyright © Microsoft Corporation. All rights reserved.

require ‘temp1’
=> true

IRTests::IRTest.new.my_method
Hi from C#
=> nil

JD

…there is no try