Google Groups Home Help | Sign in
Does .NET Interop support namespace with lower case letter ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  15 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
arton  
View profile
 More options Dec 1 2007, 11:40 am
From: arton <art...@gmail.com>
Date: Sat, 1 Dec 2007 08:40:27 -0800 (PST)
Local: Sat, Dec 1 2007 11:40 am
Subject: Does .NET Interop support namespace with lower case letter ?
Hi,
With user defined class, if the namespace name start with lower letter
case,
eg.
namespace myhumbleobjects {
    public class MyClass {
       ...
    }

}

How to use the class in ruby code ?

-----
require 'myhumbleobjects.dll'

o = myhumbleobjects::MyClass.new   # causes 'undefined local variable
or method 'myhumble...'
#or
o = Myhumbleobjects::MyClass.new # causes 'uninitialized constant ...'
------

At this moment, if Ruby.NET doesn't support the lower-cased namespace
(and class ?) , I'd like to propose that Ruby.NET should import the
name with changing the first letter into upper case (eg.
Myhumbleobjects above example) acording with Win32OLE who change the
first letter of the name of the COM object's enum value for Ruby.

Regards


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wayne Kelly  
View profile
 More options Dec 12 2007, 1:28 am
From: Wayne Kelly <w.ke...@qut.edu.au>
Date: Wed, 12 Dec 2007 16:28:10 +1000
Local: Wed, Dec 12 2007 1:28 am
Subject: RE: Does .NET Interop support namespace with lower case letter ?
Hi Arton,

Yes, I believe you are correct - we don't handle that interop case yet.

What do others think of this proposal?

Are they any other proposals?

Cheers, Wayne.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Interop: Ensure the first letter of imported classes and namespaces is upper case" by Douglas Stockwell
Douglas Stockwell  
View profile
 More options Dec 11 2007, 2:14 pm
From: Douglas Stockwell <d...@11011.net>
Date: Wed, 12 Dec 2007 04:14:32 +0900
Local: Tues, Dec 11 2007 2:14 pm
Subject: [PATCH] Interop: Ensure the first letter of imported classes and namespaces is upper case
---
 src/RubyRuntime/Interop/CLRClass.cs |   27 ++++++++++++++------
 tests/cls/namespace.rb              |   46 +++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 8 deletions(-)
 create mode 100755 tests/cls/namespace.rb

diff --git a/src/RubyRuntime/Interop/CLRClass.cs b/src/RubyRuntime/Interop/CLRClass.cs
index 3d00b1d..6b22199 100755
--- a/src/RubyRuntime/Interop/CLRClass.cs
+++ b/src/RubyRuntime/Interop/CLRClass.cs
@@ -257,6 +257,14 @@ namespace Ruby.Interop
             return klass;
         }

+        private static string FormatConstant(string name)
+        {
+            if (char.IsLower(name[0]))
+                return char.ToUpper(name[0]) + name.Substring(1);
+            else
+                return name;
+        }
+
         internal static CLRClass Load(System.Type type, Frame caller, bool makeConstant)
         {
             if (type == null)
@@ -310,11 +318,13 @@ namespace Ruby.Interop
                 {
                     foreach (string Namespace in type.Namespace.Split('.'))
                     {
-                        object innerContext;
-                        if (context.const_defined(Namespace, false) && (innerContext = context.const_get(Namespace, caller)) is Class)
-                            context = (Class)innerContext;
+                        Class innerContext;
+                        string constant = FormatConstant(Namespace);
+
+                        if (context.const_defined(constant, false) && (innerContext = context.const_get(constant, caller) as Class) != null)
+                            context = innerContext;
                         else
-                            context.define_const(Namespace, context = new CLRNamespace(Namespace));
+                            context.define_const(constant, context = new CLRNamespace(Namespace));
                     }
                 }

@@ -336,15 +346,16 @@ namespace Ruby.Interop
                     System.Type container = type.Assembly.GetType(containerName);

                     // otherwise we much build a GenericContainer
-                    if (container == null && !context.const_defined(name))
+                    if (container == null)
                     {
-                        context.define_const(name,
-                            new GenericContainer(type.Assembly, containerName, null));
+                        string constant = FormatConstant(name);
+                        if (!context.const_defined(constant))
+                            context.define_const(constant, new GenericContainer(type.Assembly, containerName, null));
                     }
                 }
                 else
                 {
-                    context.define_const(type.Name, klass);
+                    context.define_const(FormatConstant(type.Name), klass);
                 }
             }

diff --git a/tests/cls/namespace.rb b/tests/cls/namespace.rb
new file mode 100755
index 0000000..69213a8
--- /dev/null
+++ b/tests/cls/namespace.rb
@@ -0,0 +1,46 @@
+require 'mscorlib'
+require 'System'
+
+l = System::Collections::Generic::List[System::String].new
+l.Add <<"EOF";
+namespace test_lower_namespace
+{
+  public class test_lower_class
+  {
+    public static int test_lower_method()
+    {
+      return 1;
+    }
+  }
+}
+
+namespace Test_upper_namespace
+{
+  public class Test_upper_class
+  {
+    public static int Test_upper_method()
+    {
+      return 2;
+    }
+  }
+}
+EOF
+
+compiler = Microsoft::CSharp::CSharpCodeProvider.new
+cp = System::CodeDom::Compiler::CompilerParameters.new
+cp.TempFiles = System::CodeDom::Compiler::TempFileCollection.new(".")
+cp.OutputAssembly = "namespace.cs.dll"
+require compiler.CompileAssemblyFromSource(cp,l.ToArray).PathToAssembly.to_s
+
+
+require 'test/unit'
+
+class TestNamespace < Test::Unit::TestCase
+  def test_lower
+    assert_equal Test_lower_namespace::Test_lower_class.test_lower_method, 1
+  end
+
+  def test_upper
+    assert_equal Test_upper_namespace::Test_upper_class.Test_upper_method, 2
+  end
+end
--
1.5.2.2


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Loading multiple files with the same name" by Wayne Kelly
Wayne Kelly  
View profile
 More options Dec 14 2007, 1:40 am
From: Wayne Kelly <w.ke...@qut.edu.au>
Date: Fri, 14 Dec 2007 16:40:26 +1000
Local: Fri, Dec 14 2007 1:40 am
Subject: Loading multiple files with the same name

Ruby programs (such as RubyGems) can load multiple source files with the same base name (ifthey are in different directories).

Eg:
  require 'A\foo'
  require 'B\foo'

Each of these source files may have already been separately compiled into an assembly.
So, directory A might contain an assembly, presumably named foo.dll, as might directory B.

If these assembly files are named foo.dll, then presumably the assemblies will be named "foo".

.NET doesn't allow two assemblies with the same name to be loaded in the same app domain.

This seems to imply that we need to strongly name all of our generated assemblies;
and that we will need to use a different (randomly generated) key for signing each assembly.

Please tell me I'm wrong.

Can anyone think of an alternative?

Cheers, Wayne.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
M. David Peterson  
View profile
 More options Dec 14 2007, 4:43 am
From: "M. David Peterson" <xmlhac...@gmail.com>
Date: Fri, 14 Dec 2007 02:43:14 -0700
Local: Fri, Dec 14 2007 4:43 am
Subject: Re: Loading multiple files with the same name

Retry on this (sent the original messages from the wrong account)---
PLEASE NOTE: Jb has already replied, his follow-up I will attach in a
separate follow-up
---

Original Post
-------------------

This sounds like exactly what Cecil was designed for.  I've Cc'd Jb Evain,
Cecil's creator and a member of the Mono Project team.

Jb: Please see Dr. Kelly's overview of the problem at hand below.  What do
you think?  Is Cecil the way to go?

Dr. Kelly: A PDF overview of Cecil can be found @
http://evain.net/conf/Cecil-MonoMeeting07.pdf.  An overview of the latest
release and links to the source and binaries @
http://evain.net/blog/articles/2007/10/05/mono-cecil-0-6

On Dec 13, 2007 11:40 PM, Wayne Kelly <w.ke...@qut.edu.au> wrote:

--
/M:D

M. David Peterson
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: m.da...@3rdandUrban.com | m.da...@amp.fm
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
http://www.oreillynet.com/pub/au/2354


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
M. David Peterson  
View profile
 More options Dec 14 2007, 4:44 am
From: "M. David Peterson" <xmlhac...@gmail.com>
Date: Fri, 14 Dec 2007 02:44:13 -0700
Local: Fri, Dec 14 2007 4:44 am
Subject: Re: Loading multiple files with the same name

Jb's reply,
Hey,

On 12/14/07, M. David Peterson <m.da...@mdptws.com> wrote:

> Jb: Please see Dr. Kelly's overview of the problem at hand below.  What do
> you think?  Is Cecil the way to go?

Nope. Cecil is about being able to read and write assemblies, without
being tied to the runtime mechanisms. Cecil can by no mean load
assemblies and execute them.

At some point, the RubyDotNet assemblies have to be executed, and if
there's two assemblies with the same name, Cecil can't help (except if
you decide to patch the assemblies before loading time, to include a
random tag at the end of the assembly name, but that doesn't sound
like the way to go (either it is patched with Cecil or perwapi), does
it?).

--
Jb Evain  <j...@nurv.fr>

On Dec 14, 2007 2:43 AM, M. David Peterson <xmlhac...@gmail.com> wrote:

--
/M:D

M. David Peterson
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: m.da...@3rdandUrban.com | m.da...@amp.fm
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
http://www.oreillynet.com/pub/au/2354


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
M. David Peterson  
View profile
 More options Dec 14 2007, 4:59 am
From: "M. David Peterson" <xmlhac...@gmail.com>
Date: Fri, 14 Dec 2007 02:59:46 -0700
Local: Fri, Dec 14 2007 4:59 am
Subject: Re: Loading multiple files with the same name

My follow-up inline below,

On Dec 14, 2007 2:44 AM, M. David Peterson <xmlhac...@gmail.com> wrote:

> Nope. Cecil is about being able to read and write assemblies, without
> being tied to the runtime mechanisms. Cecil can by no mean load
> assemblies and execute them.

Right, but could it be used to load two separate assemblies of the same name
(of which have two completely different signatures), merge them into one
assembly (possibly separating the two using the virtual path as the
namespace? e.g. namespace net.http {...} namespace uri.http {...}),  save
the resulting assembly to disk, and then dereference calls to either
'net/http' or 'uri/http' using the virtual path to map to the namespace?  Or
am I way out in left field on this one?

> At some point, the RubyDotNet assemblies have to be executed, and if
> there's two assemblies with the same name, Cecil can't help (except if
> you decide to patch the assemblies before loading time, to include a
> random tag at the end of the assembly name, but that doesn't sound
> like the way to go (either it is patched with Cecil or perwapi), does
> it?).

Not sure.  At the moment it seems like the only real solution is generating
a random key and then signing each assembly such that they can be loaded in
the same appdomain, so if there is a solution that's cheaper than this, then
I think it's definitely worth paying some attention to.

Any ideas?

--
/M:D

M. David Peterson
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: m.da...@3rdandUrban.com | m.da...@amp.fm
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
http://www.oreillynet.com/pub/au/2354


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Swim  
View profile
 More options Dec 14 2007, 7:09 am
From: "Nathan Swim" <nathan.s...@gmail.com>
Date: Fri, 14 Dec 2007 07:09:09 -0500
Local: Fri, Dec 14 2007 7:09 am
Subject: Re: Loading multiple files with the same name

I am a complete newbie at this Ruby thing, however, it might work to include
the namespace as part of the name of the assembly.  So in your example above
'A\foo' would become A.foo.dll and, likewise, 'B\foo' would become B.foo.dll.
Where I become quite ignorant in this matter is how the 'require' command
works in Ruby.

Nathan Swim

On Dec 14, 2007 4:59 AM, M. David Peterson <xmlhac...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Douglas Stockwell  
View profile
 More options Dec 14 2007, 10:08 am
From: Douglas Stockwell <d...@11011.net>
Date: Sat, 15 Dec 2007 00:08:18 +0900
Local: Fri, Dec 14 2007 10:08 am
Subject: Re: Loading multiple files with the same name

Isn't it enough to give them a seperate assembly name, but keep the same
file name?

a\foo.dll = "foo{guid1}, v0.0.0, ..."
b\foo.dll = "foo{guid2}, v0.0.0, ..."

Doug


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
M. David Peterson  
View profile
 More options Dec 15 2007, 10:10 am
From: "M. David Peterson" <xmlhac...@gmail.com>
Date: Sat, 15 Dec 2007 08:10:18 -0700
Local: Sat, Dec 15 2007 10:10 am
Subject: Re: Loading multiple files with the same name

On 12/15/07, Jb Evain <j...@nurv.fr> wrote:

> Well, there is a of course a jillion of possibilities. Thing is that
> as Ruby's require have different semantic that assembly.load*, I think
> that it's the compiler task to handle 'require' to not accept compiled
> assemblies but to rather compile themselves relatively to the code
> that 'require' something.

Not sure I completely understand.  Are you suggesting that facilitating the
loading of pre-compiled assemblies (e.g. foo.rb and foo.dll are in the same
directory, foo.dll gets loaded if the timestamp is newer than that of foo.rb)
is a bad idea?  I can see your point from the standpoint of distributing
DLL's outside of the directory structure they were compiled against.  In
fact, I think the way Python handles things presents a perfect use-case,
using the compiled .pyc file if and when it's datestamp is newer than it .py
source file equivalent, but using the existing relative path directory
structure to determine what goes with what.
On the flip-side, however, one of key advantages of Ruby.NET is the ability
to reference statically compiled Ruby code from within any CLI-compliant
language, so while shipping a single .rb file as a DLL might be a bad idea,
shipping a complete assembly that that can be referenced from within other
languages is obviously a good thing.  That said, in the same way that Python
has adopted the notion of using eggs (which are just zipped directories that
contain the source files in their proper directory structure, replacing .zip
with .egg), I wonder if the same general idea shouldn't be considered for
Ruby.NET, using embedded resources who's key value is the virtual path of
their given directory structure.  The avenue that was taking by the
ASP.NETteam with the VirtualPathProvider I think presents a perfect
example of how
well this general idea can be adapted to the .NET platform.  e.g. >
http://msdn2.microsoft.com/en-us/library/aa479502.aspx < which is an example
of serving an entire web site from a single zip file, using the
VirtualPathProvider with VirtualFile and VirtualDirectory to decide how each
request gets handled.
Actually, come to think of it, isn't this wat netmodule's were designed for?
 I rarely use, nor rarely do I see netmodule's being used, but if not
mistaken, wasn't the original design to allow the ability to compile, for
example, a VB.NET project into a netmodule, a C# project into a netmodule,
and then merge the two (or more) together into one assembly for
distribution?

I think Cecil is the heavy gun solution here.

And you would certainly be the one qualified to make that determination ;-)
Thanks for the feedback, Jb!

--
/M:D

M. David Peterson
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: m.da...@3rdandUrban.com | m.da...@amp.fm
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
http://www.oreillynet.com/pub/au/2354


    Reply to author