Handling C# lower case namespaces

It seems like the current version does not handle lower case namespaces
when
referencing a .NET DLL. It thinks it is a method call whenever a
constant
starts with lower case. It also doesn’t handle non-alphabet characters
such
as _ (underscore).

I’m trying to call WCF service from IronRuby via the proxies file.
svcutil
converts all namespaces in the proxies file to lower case. Here’s some
info
on it:

I also noticed that “puts” does not output the value of Int64. However,
it
does if I use Console.WriteLine in my ruby program.

Just monkey-patch it:

class System::Int64

 def inspect
      self.to_string.to_s
 end

end

:wink:

On Fri, Dec 5, 2008 at 4:50 PM, Tomas M.
<[email protected]

Well, that’s very unfortunate. They seems to break .NET guidelines for
namespace naming. It’s not compatible with Ruby language to have
lowercased namespaces since they behave like modules. Module names must
start with an upper case. We can add some API to overcome this, but it
won’t be pretty. Something like

clr.class_get :foo, :bar, :baz would return class for type foo.bar.baz.

For now you can use reflection API to get the type (and Ruby class for
that type):
System::Type.get_type(“foo.bar.baz”).to_class

As for Int64… it prints #System::Int64:0x000005e, which is not
particularly useful. It should probably call ToString. I’ll file a bug.

Tomas

From: [email protected]
[mailto:[email protected]] On Behalf Of Aaron F.
Sent: Friday, December 05, 2008 1:07 PM
To: [email protected]
Subject: [Ironruby-core] Handling C# lower case namespaces

It seems like the current version does not handle lower case namespaces
when referencing a .NET DLL. It thinks it is a method call whenever a
constant starts with lower case. It also doesn’t handle non-alphabet
characters such as _ (underscore).

I’m trying to call WCF service from IronRuby via the proxies file.
svcutil converts all namespaces in the proxies file to lower case.
Here’s some info on it:

I also noticed that “puts” does not output the value of Int64. However,
it does if I use Console.WriteLine in my ruby program.

Tomas,

System::Type.get_type(“foo.bar.baz”).to_class

Are you sure that works with lower case namespaces? I tried it real
quick,
and didn’t seem to work for me. But I’ll try it again later.

Aaron

Tomas,

I tried it again. I couldn’t get the following to work with my own DLL
even
If I capitalize the namespace (It does work fine with build in types
like
System.String):

System::Type.get_type(“Abc.Hi, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null”)

Do I have any other options?

Thanks,

Aaron

I get the same behavior.
I can load types from the CLR but not from my own assembly.

I copied my assembly into the folder that contains ir.exe

require ‘mscorlib’
=> true

require ‘IronNails.Library, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null’
=> true

IronNails::View::XamlProxy
=> IronNails::View::XamlProxy

System::Type.get_type ‘IronNails.View.XamlProxy’
=> nil

System::Type.get_type ‘System.String’
=> #System::RuntimeType:0x000005c

IronNails::View::XamlProxy.to_clr_type
=> #System::RuntimeType:0x000005e

Thumbs up :slight_smile:

You might however expect this to work for all CLR types. In which case
you can indeed monkey patch it as well (kind of):

class Object
… def to_s
… self.class.name[0,8] == “System::” ? to_string.to_s : super
… end
… end
=> nil

=> nil

require ‘mscorlib’
=> true

=> nil

System::Convert.to_int64(1234)
=> 1234

Tomas

From: [email protected]
[mailto:[email protected]] On Behalf Of Michael
Letterle
Sent: Friday, December 05, 2008 1:58 PM
To: [email protected]
Subject: Re: [Ironruby-core] Handling C# lower case namespaces

Just monkey-patch it:

class System::Int64

 def inspect
      self.to_string.to_s
 end

end

:wink:

On Fri, Dec 5, 2008 at 4:50 PM, Tomas M.
<[email protected]mailto:[email protected]>
wrote:

Well, that’s very unfortunate. They seems to break .NET guidelines for
namespace naming. It’s not compatible with Ruby language to have
lowercased namespaces since they behave like modules. Module names must
start with an upper case. We can add some API to overcome this, but it
won’t be pretty. Something like

clr.class_get :foo, :bar, :baz would return class for type foo.bar.baz.

For now you can use reflection API to get the type (and Ruby class for
that type):

System::Type.get_type(“foo.bar.baz”).to_class

As for Int64… it prints #System::Int64:0x000005e, which is not
particularly useful. It should probably call ToString. I’ll file a bug.

Tomas

From:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Aaron F.
Sent: Friday, December 05, 2008 1:07 PM
To: [email protected]mailto:[email protected]
Subject: [Ironruby-core] Handling C# lower case namespaces

It seems like the current version does not handle lower case namespaces
when referencing a .NET DLL. It thinks it is a method call whenever a
constant starts with lower case. It also doesn’t handle non-alphabet
characters such as _ (underscore).

I’m trying to call WCF service from IronRuby via the proxies file.
svcutil converts all namespaces in the proxies file to lower case.
Here’s some info on it:

I also noticed that “puts” does not output the value of Int64. However,
it does if I use Console.WriteLine in my ruby program.

Yes that works

On Mon, Dec 8, 2008 at 8:11 PM, Tomas M.
<[email protected]

Can you load the assembly and get the type explicitly?

require ‘mscorlib’
System::Reflection::Assembly.Load(“IronNails.Library, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null").GetType('IronNails.View.XamlProxy’)

Tomas

From: [email protected]
[mailto:[email protected]] On Behalf Of Ivan Porto
Carrero
Sent: Monday, December 08, 2008 9:46 AM
To: [email protected]
Subject: Re: [Ironruby-core] Handling C# lower case namespaces

I get the same behavior.
I can load types from the CLR but not from my own assembly.

I copied my assembly into the folder that contains ir.exe

require ‘mscorlib’
=> true
require ‘IronNails.Library, Version=1.0.0.0http://1.0.0.0, Culture=neutral, PublicKeyToken=null’
=> true
IronNails::View::XamlProxy
=> IronNails::View::XamlProxy
System::Type.get_type ‘IronNails.View.XamlProxy’
=> nil
System::Type.get_type ‘System.String’
=> #System::RuntimeType:0x000005c
IronNails::View::XamlProxy.to_clr_type
=> #System::RuntimeType:0x000005e

On Mon, Dec 8, 2008 at 5:54 PM, Aaron F.
<[email protected]mailto:[email protected]> wrote:
Tomas,

I tried it again. I couldn’t get the following to work with my own DLL
even If I capitalize the namespace (It does work fine with build in
types like System.String):

System::Type.get_type(“Abc.Hi, Version=1.0.0.0http://1.0.0.0, Culture=neutral, PublicKeyToken=null”)

Do I have any other options?

Thanks,

Aaron


Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

You can use Assembly.LoadFile and point it to an absolute path instead.

Tomas

From: [email protected]
[mailto:[email protected]] On Behalf Of Aaron F.
Sent: Monday, December 08, 2008 12:33 PM
To: [email protected]
Subject: Re: [Ironruby-core] Handling C# lower case namespaces

Ok, I got Assembly.Load and Type.get_type both to work with my own DLL.
The actual DLL have to live where ir.exe lives. Is there a way for it
to look in the directory of the ruby file? Like the way require
statement work.

Aaron

On Mon, Dec 8, 2008 at 2:11 PM, Tomas M.
<[email protected]mailto:[email protected]>
wrote:

Can you load the assembly and get the type explicitly?

require ‘mscorlib’

System::Reflection::Assembly.Load(“IronNails.Library,
Version=1.0.0.0http://1.0.0.0, Culture=neutral,
PublicKeyToken=null”).GetType(‘IronNails.View.XamlProxy’)

Tomas

From:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Ivan Porto C.
Sent: Monday, December 08, 2008 9:46 AM

To: [email protected]mailto:[email protected]
Subject: Re: [Ironruby-core] Handling C# lower case namespaces

I get the same behavior.
I can load types from the CLR but not from my own assembly.

I copied my assembly into the folder that contains ir.exe

require ‘mscorlib’
=> true
require ‘IronNails.Library, Version=1.0.0.0http://1.0.0.0, Culture=neutral, PublicKeyToken=null’
=> true
IronNails::View::XamlProxy
=> IronNails::View::XamlProxy
System::Type.get_type ‘IronNails.View.XamlProxy’
=> nil
System::Type.get_type ‘System.String’
=> #System::RuntimeType:0x000005c
IronNails::View::XamlProxy.to_clr_type
=> #System::RuntimeType:0x000005e

On Mon, Dec 8, 2008 at 5:54 PM, Aaron F.
<[email protected]mailto:[email protected]> wrote:

Tomas,

I tried it again. I couldn’t get the following to work with my own DLL
even If I capitalize the namespace (It does work fine with build in
types like System.String):

System::Type.get_type(“Abc.Hi, Version=1.0.0.0http://1.0.0.0, Culture=neutral, PublicKeyToken=null”)

Do I have any other options?

Thanks,

Aaron


Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

Hi Aaron!

I’m doing this way for now:

require ‘…/…/your_folder/your_assembly.dll’

?

2008/12/8 Aaron F. [email protected]:

Ok, I got Assembly.Load and Type.get_type both to work with my own DLL.
The actual DLL have to live where ir.exe lives. Is there a way for it
to
look in the directory of the ruby file? Like the way require statement
work.

Aaron

On Mon, Dec 8, 2008 at 2:11 PM, Tomas M.
<[email protected]

I tried to load the struct the same way, but I don’t know how to set the
value of it. For example:

C#

namespace x.y.z {
public struct Foo {
public long Bar;
public Foo(long bar) {
this.Bar = bar;
}
}
}

var foo = new x.y.z.Foo(1);

IronRuby

Foo = Type.get_type(“x.y.z.Foo, MyAssembly, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null”, true).to_class

how do I do the equivalent of

var foo = new x.y.z.Foo(1); ?

Aaron

On Mon, Dec 8, 2008 at 3:45 PM, Tomas M.
<[email protected]

Normally
foo = x::y::z::Foo.new(1)

in the console you need to use global variables:$foo =
x::y::z::Foo.new(1)

Welcome to the “wonderful” world of Fusion.
If you use Assembly.LoadFrom, then you can only use the assembly
reference
itself to get the types. The canonical names don’t match assemblies
loaded
using LoadFrom. To use Assembly.Load, it has to be in one of the
approved
search paths (which, by default, is the path of the launching executable
only, plus the GAC of course).

We went through an almost excruciating amount of pain with assembly load
paths and such to make all this work correctly in xUnit.net.


Brad http://bradwilson.typepad.com/

Ivan,

In this case you actually can’t do foo = x::y::z::Foo.new(1) because
IronRuby doesn’t support lowercase namespace. It think it’s a method
call.

That’s why I started out
Foo = Type.get_type(“x.y.z.Foo, MyAssembly, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null”, true).to_class

Aaron