Hi Alexander,

did you try to convert the strings in the hash (which are a special type 
of string called mutablestring) to a System::String.

I usually use:

a = "This is A String"
print a.class  # => String
print a.to_clr_string   # => System::String (which is the standard .net 
string type)

I would use:
hashString = ModuleClass.GetObjectHash(testObject).to_s.to_clr_string

(now hashString is a Standard C# string)



Alexander Ranger wrote in post #1070241:
> I'm using IronRuby 1.1.3 and .Net 4.
>
> In IronRuby I've got two files:
> 1) Module.rb
> # This file contains a class with static method GetObjectHash. The idea
> is to parse the object find all it's properties and make a hash like:
> {property_name => [property_type, property_value], ...}
>
> 2) Main.rb
> # This file creates several objects from different classes and calls
> GetObjectHash method.
>
> Then I try to execute Main.rb using C#:
>
> string path = "../../RubyTest.rb";
> var runtime = IronRuby.Ruby.CreateRuntime();
> var engine = runtime.GetEngine("rb");
> engine.ExecuteFile(path);
>
> Ok, it executes. And if in Main.rb I write the last command as
>
> hashString = ModuleClass.GetObjectHash(testObject).to_s

> print hashString
>
> it prints into the console the hash I want to see. But. I'd like not to
> use the last "print" command, and get the hashString variable into C#
> where I can use it as normal string.
>
> I tried to do that like:
>
> dynamic netString;
> engine.ExecuteFile(path).TryGetVariable("hashString", out netString);
> string hash = netString as String;
> Console.WriteLine(hash);
>
> But hashString remained null. (Variable name is ok, I checked it).
>
> Am I doing something wrong? How can I get "hashString" with stored data
> into C#?

-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to