[Ironruby-core] Comparing CLR strings and Ruby strings - a slightly surprising behaviour

Meinrad Recheis meinrad.recheis at gmail.com
Tue Mar 3 19:24:32 EST 2009


Ok, the Execute<T> is convenient enough. In my opinion the highlighted C#
code represents a potential interoperability pitfall and will need to be
documented well. On the ruby side, I think there are no technical
limitations to achieve ruby's string behavior even if the underlying object
is an immutable clr string. What do you think?
-- henon

On Wed, Mar 4, 2009 at 12:24 AM, Tomas Matousek <
Tomas.Matousek at microsoft.com> wrote:

>  We don’t plan to make the highlighted code work. However we are going to
> make this work:
>
>
>
> string s = engine.Execute<string>(“’hi’”)
>
>
>
> and also this works:
>
>
>
> string s = engine.Execute(“’hi’”).ToString(),
>
>
>
> although in this case you need to take care of *null*.
>
>
>
> The difference is that unlike Execute, Execute<T> invokes an explicit
> dynamic conversion on the resulting type. You can achieve the same using
> engine.ObjectOperations.ConvertTo<string>(engine.Execute(“’hi’”)).
>
>
>
> Tomas
>

[...]

>  In addition to that, it would also be great to have automatic type
> conversion on the .NET side too. I'd expect to be able to assign a string
> pulled out from the interpreter to a C# string without the need to call
> ToString(). For example,
>
> string s = engine.Execute("'hi'") as string;
>
> Currently s would be null because the dynamic cast to System.String fails.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090304/9e713685/attachment.html>


More information about the Ironruby-core mailing list