<div dir="ltr">You should call generic methods a bit differently. <div><br></div><div>The next code works:<div>ret_val = c.method(:do_something_else).of(String).call(str)</div><div><br></div><div>Shay.</div><div>--------------------------------------------------------<br>
Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center<br>Blog: http://IronShay.com | Twitter: <a href="http://twitter.com/ironshay">http://twitter.com/ironshay</a> <br>
<br><br><div class="gmail_quote">On Thu, Feb 11, 2010 at 4:44 PM, Michael Erasmus <span dir="ltr"><<a href="mailto:michaelerasmus@gmail.com">michaelerasmus@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Thanks Shay.<div><br></div><div>OK your code works. But my trouble seems to come in with the Generic method. </div><div><br></div><div>When I do:<div><br></div><div><div><div class="im"><div>public class Class1</div><div>
{</div><div> public string DoSomething(ref string test)</div>
<div> {</div><div> test = test + "tamtamtam";</div><div><br></div><div> return "return value";</div><div> }</div><div><br></div></div><div> public string DoSomethingElse<T>(ref T test)</div>
<div> {</div><div> return test.ToString(); </div><div> }</div><div> }</div></div><div><br></div>and then call it from IR:</div><div><br></div><div><br></div><div><div><div>>>> c = TestClass::Class1.new</div>
<div>=> TestClass.Class1</div><div>>>> c.do_something("Bla")</div><div>=> ['return value', 'Blatamtamtam']</div><div>>>> c.do_something_else("Bla")</div><div class="im">
<div>Microsoft.Scripting.Core:0:in `Bind': Expression of type 'IronRuby.Builtins.Muta</div>
<div>bleString&' cannot be used for parameter of type 'IronRuby.Builtins.MutableStrin</div></div><div>g' of method 'System.String DoSomethingElse[MutableString](IronRuby.Builtins.Mut</div><div>ableString ByRef)' (ArgumentError)</div>
<div class="im">
<div> from Microsoft.Scripting.Core:0:in `BindCore'</div></div><div> from :0</div><div><br></div><div><br></div><div><br></div></div><div><div></div><div class="h5"><div><br></div><div class="gmail_quote">
On Thu, Feb 11, 2010 at 4:12 PM, Shay Friedman <span dir="ltr"><<a href="mailto:shay.friedman@gmail.com" target="_blank">shay.friedman@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>It returns another return value with the new ref value.</div><div><br></div><div>For example, if you have the next c# class:</div>
<div><div>public class Class1</div><div>{</div><div> public string DoSomething(ref string test)</div>
<div> {</div><div> test = test + "tamtamtam";</div><div><br></div><div> return "return value";</div><div> }</div><div>}</div><div><br></div><div>This is the IronRuby code you can write to use it:</div>
<div><div>>>> require 'c:\dev\TestApps\TestClass\TestClass\bin\Debug\TestClass.dll'</div><div>=> true</div><div>>>> c = Class1.new</div><div>=> TestClass.Class1</div><div>>>> str = "hello"</div>
<div>=> "hello"</div><div>>>> result = c.do_something(str)</div><div>=> ['return value', 'hellotamtamtam']</div><div><br></div><div>Pay attention that the result variable is an array that contains the method return value as the first item and the ref value as the second parameter.</div>
<div><br></div><div>Shay.</div></div></div>--------------------------------------------------------<br>Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center<br>Blog: http://IronShay.com | Twitter: <a href="http://twitter.com/ironshay" target="_blank">http://twitter.com/ironshay</a> <br>
<br><br><div class="gmail_quote"><div><div></div><div>On Thu, Feb 11, 2010 at 3:44 PM, Michael Erasmus <span dir="ltr"><<a href="mailto:michaelerasmus@gmail.com" target="_blank">michaelerasmus@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>
Hi Everyone,<div><br></div><div>I'm trying to write a IronRuby script that interops with a a .NET assembly written in C#. </div><div><br></div><div>It has a class that derives from a base class in the .NET assembly. One of the base class protected methods looks like this:</div>
<div><br></div><div><div>protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, T value)</div><div> {</div><div> ......</div><div> }</div><div><br></div><div>I can't for the life of me figure out how to call this method from IR in my derived class.</div>
<div>The documentation mentions that you can call <b>out </b>parameters without using them as arguments, but I can't seem to find anything about <b>ref </b>params.</div><div><br></div><div>If I just try calling the method like this:</div>
<div><br></div><div>OnNotifyPropertyChanged(property_name, value, value)</div><div><br></div><div>I get this error:</div><div><br></div><div><div><i>Microsoft.Scripting.Core:0:in `Bind': Expression of type 'IronRuby.Builtins.Muta</i></div>
<div><i>bleString&' cannot be used for parameter of type 'IronRuby.Builtins.MutableStrin</i></div><div><i>g' of method 'Void #base#OnNotifyPropertyChanged[MutableString](System.String, I</i></div><div>
<i>ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)' (Argumen</i></div><div><i>tError)</i></div><div><i> from Microsoft.Scripting.Core:0:in `BindCore'</i></div><div><i> from ./dynamic_event_item.rb:22:in `method_missing'</i></div>
<div><i> from :0</i></div><div><br></div><div><br></div><div>Am I missing something?</div><div><br></div><div>Thanks</div><div><br></div><div>Michael Erasmus</div><div><br></div></div></div>
<br></div></div>_______________________________________________<br>
Ironruby-core mailing list<br>
<a href="mailto:Ironruby-core@rubyforge.org" target="_blank">Ironruby-core@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/ironruby-core" target="_blank">http://rubyforge.org/mailman/listinfo/ironruby-core</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Ironruby-core mailing list<br>
<a href="mailto:Ironruby-core@rubyforge.org" target="_blank">Ironruby-core@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/ironruby-core" target="_blank">http://rubyforge.org/mailman/listinfo/ironruby-core</a><br>
<br></blockquote></div><br></div></div></div></div>
<br>_______________________________________________<br>
Ironruby-core mailing list<br>
<a href="mailto:Ironruby-core@rubyforge.org">Ironruby-core@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/ironruby-core" target="_blank">http://rubyforge.org/mailman/listinfo/ironruby-core</a><br>
<br></blockquote></div><br></div></div></div>