Thibaut Barrère
2009-Apr-02 14:35 UTC
[Ironruby-core] How to instanciate a System::String[] from IronRuby?
Hi, while trying to call some C# code from IronRuby, I get this: my_csharp_class_instance.call(%w(some array)) :0: can''t convert Array into System::String[] (TypeError) Is there some easy way to construct an array of System::String ? Or a conversion ? cheers, -- Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090402/a0a72bc6/attachment-0001.html>
Curt Hagenlocher
2009-Apr-02 15:03 UTC
[Ironruby-core] How to instanciate a System::String[] from IronRuby?
I don''t know if it''s the easiest way, but this should work as
a conversion:
x = [''a'', ''b'', ''c'']
System::Array[System::String].new(x.map { |s| s.to_s.to_clr_string })
(Obviously, if you know that the elements are already Ruby strings, you can omit
the "to_s".)
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Thibaut Barr?re
Sent: Thursday, April 02, 2009 7:36 AM
To: ironruby-core
Subject: [Ironruby-core] How to instanciate a System::String[] from IronRuby?
Hi,
while trying to call some C# code from IronRuby, I get this:
my_csharp_class_instance.call(%w(some array))
:0: can''t convert Array into System::String[] (TypeError)
Is there some easy way to construct an array of System::String ? Or a conversion
?
cheers,
-- Thibaut
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20090402/66587491/attachment.html>
Michael Letterle
2009-Apr-02 15:20 UTC
[Ironruby-core] How to instanciate a System::String[] from IronRuby?
class Array
def to_clr_arr
arr = System::Array.CreateInstance self[0].class.to_clr_type,
System::Int32.pase(self.length.to_s)
self.each_with_index { |r, i| arr[i] = r }
return arr
end
end
my_csharp_class_instance.call(%w(some array).map{|x|
x.to_clr_string}.to_clr_arr)
2009/4/2 Thibaut Barr?re <thibaut.barrere at gmail.com>
> Hi,
>
> while trying to call some C# code from IronRuby, I get this:
>
> my_csharp_class_instance.call(%w(some array))
>
> :0: can''t convert Array into System::String[] (TypeError)
>
> Is there some easy way to construct an array of System::String ? Or a
> conversion ?
>
> cheers,
>
> -- Thibaut
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>
--
Michael Letterle
IronRuby MVP
http://blog.prokrams.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20090402/9bb98072/attachment.html>
Jim Deville
2009-Apr-02 15:41 UTC
[Ironruby-core] How to instanciate a System::String[] from IronRuby?
Jimmy and I have discussed a to_clr_array(type) where type defaults to Object,
but nothing like that exists yet.
JD
________________________________
From: ironruby-core-bounces at rubyforge.org [ironruby-core-bounces at
rubyforge.org] on behalf of Curt Hagenlocher [curth at microsoft.com]
Sent: Thursday, April 02, 2009 8:03 AM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] How to instanciate a System::String[] from
IronRuby?
I don?t know if it?s the easiest way, but this should work as a conversion:
x = [''a'', ''b'', ''c'']
System::Array[System::String].new(x.map { |s| s.to_s.to_clr_string })
(Obviously, if you know that the elements are already Ruby strings, you can omit
the ?to_s?.)
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Thibaut Barr?re
Sent: Thursday, April 02, 2009 7:36 AM
To: ironruby-core
Subject: [Ironruby-core] How to instanciate a System::String[] from IronRuby?
Hi,
while trying to call some C# code from IronRuby, I get this:
my_csharp_class_instance.call(%w(some array))
:0: can''t convert Array into System::String[] (TypeError)
Is there some easy way to construct an array of System::String ? Or a conversion
?
cheers,
-- Thibaut
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20090402/4fb06e01/attachment.html>
Tomas Matousek
2009-Apr-02 16:24 UTC
[Ironruby-core] How to instanciate a System::String[] from IronRuby?
This is the right way:
x = [''a'', ''b'', ''c'']
System::Array[System::String].new(x.map { |s| s.to_s.to_clr_string })
This would simplify to
x = [''a'', ''b'', ''c'']
System::Array[System::String].new(x)
As soon as we implement implicit conversions here.
Tomas
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Jim Deville
Sent: Thursday, April 02, 2009 8:41 AM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] How to instanciate a System::String[] from
IronRuby?
Jimmy and I have discussed a to_clr_array(type) where type defaults to Object,
but nothing like that exists yet.
JD
________________________________
From: ironruby-core-bounces at rubyforge.org [ironruby-core-bounces at
rubyforge.org] on behalf of Curt Hagenlocher [curth at microsoft.com]
Sent: Thursday, April 02, 2009 8:03 AM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] How to instanciate a System::String[] from
IronRuby?
I don''t know if it''s the easiest way, but this should work as
a conversion:
x = [''a'', ''b'', ''c'']
System::Array[System::String].new(x.map { |s| s.to_s.to_clr_string })
(Obviously, if you know that the elements are already Ruby strings, you can omit
the "to_s".)
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Thibaut Barr?re
Sent: Thursday, April 02, 2009 7:36 AM
To: ironruby-core
Subject: [Ironruby-core] How to instanciate a System::String[] from IronRuby?
Hi,
while trying to call some C# code from IronRuby, I get this:
my_csharp_class_instance.call(%w(some array))
:0: can''t convert Array into System::String[] (TypeError)
Is there some easy way to construct an array of System::String ? Or a conversion
?
cheers,
-- Thibaut
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20090402/d7859790/attachment-0001.html>
Thibaut Barrère
2009-Apr-02 22:51 UTC
[Ironruby-core] How to instanciate a System::String[] from IronRuby?
Hi, thanks for the feedback - I''ll give these a go. cheers -- Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090403/44b18297/attachment.html>