Michael Erasmus
2010-Feb-11 13:44 UTC
[Ironruby-core] Calling a C# method with a byref parameter
Hi Everyone, I''m trying to write a IronRuby script that interops with a a .NET assembly written in C#. It has a class that derives from a base class in the .NET assembly. One of the base class protected methods looks like this: protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, T value) { ...... } I can''t for the life of me figure out how to call this method from IR in my derived class. The documentation mentions that you can call *out *parameters without using them as arguments, but I can''t seem to find anything about *ref *params. If I just try calling the method like this: OnNotifyPropertyChanged(property_name, value, value) I get this error: *Microsoft.Scripting.Core:0:in `Bind'': Expression of type ''IronRuby.Builtins.Muta* *bleString&'' cannot be used for parameter of type ''IronRuby.Builtins.MutableStrin* *g'' of method ''Void #base#OnNotifyPropertyChanged[MutableString](System.String, I* *ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)'' (Argumen* *tError)* * from Microsoft.Scripting.Core:0:in `BindCore''* * from ./dynamic_event_item.rb:22:in `method_missing''* * from :0* Am I missing something? Thanks Michael Erasmus -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100211/37bc6165/attachment.html>
Shay Friedman
2010-Feb-11 14:12 UTC
[Ironruby-core] Calling a C# method with a byref parameter
It returns another return value with the new ref value. For example, if you have the next c# class: public class Class1 { public string DoSomething(ref string test) { test = test + "tamtamtam"; return "return value"; } } This is the IronRuby code you can write to use it:>>> require ''c:\dev\TestApps\TestClass\TestClass\bin\Debug\TestClass.dll''=> true>>> c = Class1.new=> TestClass.Class1>>> str = "hello"=> "hello">>> result = c.do_something(str)=> [''return value'', ''hellotamtamtam''] 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. Shay. -------------------------------------------------------- Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay On Thu, Feb 11, 2010 at 3:44 PM, Michael Erasmus <michaelerasmus at gmail.com>wrote:> Hi Everyone, > > I''m trying to write a IronRuby script that interops with a a .NET assembly > written in C#. > > It has a class that derives from a base class in the .NET assembly. One of > the base class protected methods looks like this: > > protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, T > value) > { > ...... > } > > I can''t for the life of me figure out how to call this method from IR in my > derived class. > The documentation mentions that you can call *out *parameters without > using them as arguments, but I can''t seem to find anything about *ref * > params. > > If I just try calling the method like this: > > OnNotifyPropertyChanged(property_name, value, value) > > I get this error: > > *Microsoft.Scripting.Core:0:in `Bind'': Expression of type > ''IronRuby.Builtins.Muta* > *bleString&'' cannot be used for parameter of type > ''IronRuby.Builtins.MutableStrin* > *g'' of method ''Void > #base#OnNotifyPropertyChanged[MutableString](System.String, I* > *ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)'' > (Argumen* > *tError)* > * from Microsoft.Scripting.Core:0:in `BindCore''* > * from ./dynamic_event_item.rb:22:in `method_missing''* > * from :0* > > > Am I missing something? > > Thanks > > Michael Erasmus > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100211/c30940be/attachment.html>
Michael Erasmus
2010-Feb-11 14:44 UTC
[Ironruby-core] Calling a C# method with a byref parameter
Thanks Shay. OK your code works. But my trouble seems to come in with the Generic method. When I do: public class Class1 { public string DoSomething(ref string test) { test = test + "tamtamtam"; return "return value"; } public string DoSomethingElse<T>(ref T test) { return test.ToString(); } } and then call it from IR:>>> c = TestClass::Class1.new=> TestClass.Class1>>> c.do_something("Bla")=> [''return value'', ''Blatamtamtam'']>>> c.do_something_else("Bla")Microsoft.Scripting.Core:0:in `Bind'': Expression of type ''IronRuby.Builtins.Muta bleString&'' cannot be used for parameter of type ''IronRuby.Builtins.MutableStrin g'' of method ''System.String DoSomethingElse[MutableString](IronRuby.Builtins.Mut ableString ByRef)'' (ArgumentError) from Microsoft.Scripting.Core:0:in `BindCore'' from :0 On Thu, Feb 11, 2010 at 4:12 PM, Shay Friedman <shay.friedman at gmail.com>wrote:> It returns another return value with the new ref value. > > For example, if you have the next c# class: > public class Class1 > { > public string DoSomething(ref string test) > { > test = test + "tamtamtam"; > > return "return value"; > } > } > > This is the IronRuby code you can write to use it: > >>> require ''c:\dev\TestApps\TestClass\TestClass\bin\Debug\TestClass.dll'' > => true > >>> c = Class1.new > => TestClass.Class1 > >>> str = "hello" > => "hello" > >>> result = c.do_something(str) > => [''return value'', ''hellotamtamtam''] > > 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. > > Shay. > -------------------------------------------------------- > Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | > Sela Technology Center > Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay > > > On Thu, Feb 11, 2010 at 3:44 PM, Michael Erasmus <michaelerasmus at gmail.com > > wrote: > >> Hi Everyone, >> >> I''m trying to write a IronRuby script that interops with a a .NET assembly >> written in C#. >> >> It has a class that derives from a base class in the .NET assembly. One of >> the base class protected methods looks like this: >> >> protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, >> T value) >> { >> ...... >> } >> >> I can''t for the life of me figure out how to call this method from IR in >> my derived class. >> The documentation mentions that you can call *out *parameters without >> using them as arguments, but I can''t seem to find anything about *ref * >> params. >> >> If I just try calling the method like this: >> >> OnNotifyPropertyChanged(property_name, value, value) >> >> I get this error: >> >> *Microsoft.Scripting.Core:0:in `Bind'': Expression of type >> ''IronRuby.Builtins.Muta* >> *bleString&'' cannot be used for parameter of type >> ''IronRuby.Builtins.MutableStrin* >> *g'' of method ''Void >> #base#OnNotifyPropertyChanged[MutableString](System.String, I* >> *ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)'' >> (Argumen* >> *tError)* >> * from Microsoft.Scripting.Core:0:in `BindCore''* >> * from ./dynamic_event_item.rb:22:in `method_missing''* >> * from :0* >> >> >> Am I missing something? >> >> Thanks >> >> Michael Erasmus >> >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100211/8b981e7a/attachment.html>
Shay Friedman
2010-Feb-11 14:52 UTC
[Ironruby-core] Calling a C# method with a byref parameter
You should call generic methods a bit differently. The next code works: ret_val = c.method(:do_something_else).of(String).call(str) Shay. -------------------------------------------------------- Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay On Thu, Feb 11, 2010 at 4:44 PM, Michael Erasmus <michaelerasmus at gmail.com>wrote:> Thanks Shay. > > OK your code works. But my trouble seems to come in with the Generic > method. > > When I do: > > public class Class1 > { > public string DoSomething(ref string test) > { > test = test + "tamtamtam"; > > return "return value"; > } > > public string DoSomethingElse<T>(ref T test) > { > return test.ToString(); > } > } > > and then call it from IR: > > > >>> c = TestClass::Class1.new > => TestClass.Class1 > >>> c.do_something("Bla") > => [''return value'', ''Blatamtamtam''] > >>> c.do_something_else("Bla") > Microsoft.Scripting.Core:0:in `Bind'': Expression of type > ''IronRuby.Builtins.Muta > bleString&'' cannot be used for parameter of type > ''IronRuby.Builtins.MutableStrin > g'' of method ''System.String > DoSomethingElse[MutableString](IronRuby.Builtins.Mut > ableString ByRef)'' (ArgumentError) > from Microsoft.Scripting.Core:0:in `BindCore'' > from :0 > > > > > On Thu, Feb 11, 2010 at 4:12 PM, Shay Friedman <shay.friedman at gmail.com>wrote: > >> It returns another return value with the new ref value. >> >> For example, if you have the next c# class: >> public class Class1 >> { >> public string DoSomething(ref string test) >> { >> test = test + "tamtamtam"; >> >> return "return value"; >> } >> } >> >> This is the IronRuby code you can write to use it: >> >>> require ''c:\dev\TestApps\TestClass\TestClass\bin\Debug\TestClass.dll'' >> => true >> >>> c = Class1.new >> => TestClass.Class1 >> >>> str = "hello" >> => "hello" >> >>> result = c.do_something(str) >> => [''return value'', ''hellotamtamtam''] >> >> 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. >> >> Shay. >> -------------------------------------------------------- >> Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | >> Sela Technology Center >> Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay >> >> >> On Thu, Feb 11, 2010 at 3:44 PM, Michael Erasmus < >> michaelerasmus at gmail.com> wrote: >> >>> Hi Everyone, >>> >>> I''m trying to write a IronRuby script that interops with a a .NET >>> assembly written in C#. >>> >>> It has a class that derives from a base class in the .NET assembly. One >>> of the base class protected methods looks like this: >>> >>> protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, >>> T value) >>> { >>> ...... >>> } >>> >>> I can''t for the life of me figure out how to call this method from IR in >>> my derived class. >>> The documentation mentions that you can call *out *parameters without >>> using them as arguments, but I can''t seem to find anything about *ref * >>> params. >>> >>> If I just try calling the method like this: >>> >>> OnNotifyPropertyChanged(property_name, value, value) >>> >>> I get this error: >>> >>> *Microsoft.Scripting.Core:0:in `Bind'': Expression of type >>> ''IronRuby.Builtins.Muta* >>> *bleString&'' cannot be used for parameter of type >>> ''IronRuby.Builtins.MutableStrin* >>> *g'' of method ''Void >>> #base#OnNotifyPropertyChanged[MutableString](System.String, I* >>> *ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)'' >>> (Argumen* >>> *tError)* >>> * from Microsoft.Scripting.Core:0:in `BindCore''* >>> * from ./dynamic_event_item.rb:22:in `method_missing''* >>> * from :0* >>> >>> >>> Am I missing something? >>> >>> Thanks >>> >>> Michael Erasmus >>> >>> >>> _______________________________________________ >>> Ironruby-core mailing list >>> Ironruby-core at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/ironruby-core >>> >>> >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100211/3030f2c4/attachment-0001.html>
Jim Deville
2010-Feb-11 15:55 UTC
[Ironruby-core] Calling a C# method with a byref parameter
That call actually should (usually) be able to infer the type. Please file a bug on codeplex that Generic Type inference isn''t working with ByRef types. JD From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shay Friedman Sent: Thursday, February 11, 2010 6:53 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Calling a C# method with a byref parameter You should call generic methods a bit differently. The next code works: ret_val = c.method(:do_something_else).of(String).call(str) Shay. -------------------------------------------------------- Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay On Thu, Feb 11, 2010 at 4:44 PM, Michael Erasmus <michaelerasmus at gmail.com<mailto:michaelerasmus at gmail.com>> wrote: Thanks Shay. OK your code works. But my trouble seems to come in with the Generic method. When I do: public class Class1 { public string DoSomething(ref string test) { test = test + "tamtamtam"; return "return value"; } public string DoSomethingElse<T>(ref T test) { return test.ToString(); } } and then call it from IR:>>> c = TestClass::Class1.new=> TestClass.Class1>>> c.do_something("Bla")=> [''return value'', ''Blatamtamtam'']>>> c.do_something_else("Bla")Microsoft.Scripting.Core:0:in `Bind'': Expression of type ''IronRuby.Builtins.Muta bleString&'' cannot be used for parameter of type ''IronRuby.Builtins.MutableStrin g'' of method ''System.String DoSomethingElse[MutableString](IronRuby.Builtins.Mut ableString ByRef)'' (ArgumentError) from Microsoft.Scripting.Core:0:in `BindCore'' from :0 On Thu, Feb 11, 2010 at 4:12 PM, Shay Friedman <shay.friedman at gmail.com<mailto:shay.friedman at gmail.com>> wrote: It returns another return value with the new ref value. For example, if you have the next c# class: public class Class1 { public string DoSomething(ref string test) { test = test + "tamtamtam"; return "return value"; } } This is the IronRuby code you can write to use it:>>> require ''c:\dev\TestApps\TestClass\TestClass\bin\Debug\TestClass.dll''=> true>>> c = Class1.new=> TestClass.Class1>>> str = "hello"=> "hello">>> result = c.do_something(str)=> [''return value'', ''hellotamtamtam''] 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. Shay. -------------------------------------------------------- Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay On Thu, Feb 11, 2010 at 3:44 PM, Michael Erasmus <michaelerasmus at gmail.com<mailto:michaelerasmus at gmail.com>> wrote: Hi Everyone, I''m trying to write a IronRuby script that interops with a a .NET assembly written in C#. It has a class that derives from a base class in the .NET assembly. One of the base class protected methods looks like this: protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, T value) { ...... } I can''t for the life of me figure out how to call this method from IR in my derived class. The documentation mentions that you can call out parameters without using them as arguments, but I can''t seem to find anything about ref params. If I just try calling the method like this: OnNotifyPropertyChanged(property_name, value, value) I get this error: Microsoft.Scripting.Core:0:in `Bind'': Expression of type ''IronRuby.Builtins.Muta bleString&'' cannot be used for parameter of type ''IronRuby.Builtins.MutableStrin g'' of method ''Void #base#OnNotifyPropertyChanged[MutableString](System.String, I ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)'' (Argumen tError) from Microsoft.Scripting.Core:0:in `BindCore'' from ./dynamic_event_item.rb:22:in `method_missing'' from :0 Am I missing something? Thanks Michael Erasmus _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100211/0be899a0/attachment.html>
Ryan Riley
2010-Feb-11 17:56 UTC
[Ironruby-core] Calling a C# method with a byref parameter
On what types will IR be able to infer the types? Is that documented on the site and I just didn''t see it? Ryan Riley On Thu, Feb 11, 2010 at 9:55 AM, Jim Deville <jdeville at microsoft.com> wrote:> That call actually should (usually) be able to infer the type. Please file > a bug on codeplex that Generic Type inference isn?t working with ByRef > types. > > > > JD > > > > *From:* ironruby-core-bounces at rubyforge.org [mailto: > ironruby-core-bounces at rubyforge.org] *On Behalf Of *Shay Friedman > *Sent:* Thursday, February 11, 2010 6:53 AM > *To:* ironruby-core at rubyforge.org > *Subject:* Re: [Ironruby-core] Calling a C# method with a byref parameter > > > > You should call generic methods a bit differently. > > > > The next code works: > > ret_val = c.method(:do_something_else).of(String).call(str) > > > > Shay. > > -------------------------------------------------------- > Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | > Sela Technology Center > Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay > > On Thu, Feb 11, 2010 at 4:44 PM, Michael Erasmus <michaelerasmus at gmail.com> > wrote: > > Thanks Shay. > > > > OK your code works. But my trouble seems to come in with the Generic > method. > > > > When I do: > > > > public class Class1 > > { > > public string DoSomething(ref string test) > > { > > test = test + "tamtamtam"; > > > > return "return value"; > > } > > > > public string DoSomethingElse<T>(ref T test) > > { > > return test.ToString(); > > } > > } > > > > and then call it from IR: > > > > > > >>> c = TestClass::Class1.new > > => TestClass.Class1 > > >>> c.do_something("Bla") > > => [''return value'', ''Blatamtamtam''] > > >>> c.do_something_else("Bla") > > Microsoft.Scripting.Core:0:in `Bind'': Expression of type > ''IronRuby.Builtins.Muta > > bleString&'' cannot be used for parameter of type > ''IronRuby.Builtins.MutableStrin > > g'' of method ''System.String > DoSomethingElse[MutableString](IronRuby.Builtins.Mut > > ableString ByRef)'' (ArgumentError) > > from Microsoft.Scripting.Core:0:in `BindCore'' > > from :0 > > > > > > > > > > On Thu, Feb 11, 2010 at 4:12 PM, Shay Friedman <shay.friedman at gmail.com> > wrote: > > It returns another return value with the new ref value. > > > > For example, if you have the next c# class: > > public class Class1 > > { > > public string DoSomething(ref string test) > > { > > test = test + "tamtamtam"; > > > > return "return value"; > > } > > } > > > > This is the IronRuby code you can write to use it: > > >>> require ''c:\dev\TestApps\TestClass\TestClass\bin\Debug\TestClass.dll'' > > => true > > >>> c = Class1.new > > => TestClass.Class1 > > >>> str = "hello" > > => "hello" > > >>> result = c.do_something(str) > > => [''return value'', ''hellotamtamtam''] > > > > 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. > > > > Shay. > > -------------------------------------------------------- > Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | > Sela Technology Center > Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay > > On Thu, Feb 11, 2010 at 3:44 PM, Michael Erasmus <michaelerasmus at gmail.com> > wrote: > > Hi Everyone, > > > > I''m trying to write a IronRuby script that interops with a a .NET assembly > written in C#. > > > > It has a class that derives from a base class in the .NET assembly. One of > the base class protected methods looks like this: > > > > protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, T > value) > > { > > ...... > > } > > > > I can''t for the life of me figure out how to call this method from IR in my > derived class. > > The documentation mentions that you can call *out *parameters without > using them as arguments, but I can''t seem to find anything about *ref * > params. > > > > If I just try calling the method like this: > > > > OnNotifyPropertyChanged(property_name, value, value) > > > > I get this error: > > > > *Microsoft.Scripting.Core:0:in `Bind'': Expression of type > ''IronRuby.Builtins.Muta* > > *bleString&'' cannot be used for parameter of type > ''IronRuby.Builtins.MutableStrin* > > *g'' of method ''Void > #base#OnNotifyPropertyChanged[MutableString](System.String, I* > > *ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)'' > (Argumen* > > *tError)* > > * from Microsoft.Scripting.Core:0:in `BindCore''* > > * from ./dynamic_event_item.rb:22:in `method_missing''* > > * from :0* > > > > > > Am I missing something? > > > > Thanks > > > > Michael Erasmus > > > > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100211/48ef9698/attachment-0001.html>
Michael Erasmus
2010-Feb-12 13:17 UTC
[Ironruby-core] Calling a C# method with a byref parameter
Ok, thanks Jim. I have filed a bug here: http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3934 <http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3934>I also noticed that event when using the form method(:name).Of(String).Call(param) If you''re calling a protected method from a derived class like this you''ll get a ArgumentError. On Thu, Feb 11, 2010 at 7:56 PM, Ryan Riley <ryan.riley at panesofglass.org>wrote:> On what types will IR be able to infer the types? Is that documented on the > site and I just didn''t see it? > > Ryan Riley > > > > On Thu, Feb 11, 2010 at 9:55 AM, Jim Deville <jdeville at microsoft.com>wrote: > >> That call actually should (usually) be able to infer the type. Please file >> a bug on codeplex that Generic Type inference isn?t working with ByRef >> types. >> >> >> >> JD >> >> >> >> *From:* ironruby-core-bounces at rubyforge.org [mailto: >> ironruby-core-bounces at rubyforge.org] *On Behalf Of *Shay Friedman >> *Sent:* Thursday, February 11, 2010 6:53 AM >> *To:* ironruby-core at rubyforge.org >> *Subject:* Re: [Ironruby-core] Calling a C# method with a byref parameter >> >> >> >> You should call generic methods a bit differently. >> >> >> >> The next code works: >> >> ret_val = c.method(:do_something_else).of(String).call(str) >> >> >> >> Shay. >> >> -------------------------------------------------------- >> Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | >> Sela Technology Center >> Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay >> >> On Thu, Feb 11, 2010 at 4:44 PM, Michael Erasmus < >> michaelerasmus at gmail.com> wrote: >> >> Thanks Shay. >> >> >> >> OK your code works. But my trouble seems to come in with the Generic >> method. >> >> >> >> When I do: >> >> >> >> public class Class1 >> >> { >> >> public string DoSomething(ref string test) >> >> { >> >> test = test + "tamtamtam"; >> >> >> >> return "return value"; >> >> } >> >> >> >> public string DoSomethingElse<T>(ref T test) >> >> { >> >> return test.ToString(); >> >> } >> >> } >> >> >> >> and then call it from IR: >> >> >> >> >> >> >>> c = TestClass::Class1.new >> >> => TestClass.Class1 >> >> >>> c.do_something("Bla") >> >> => [''return value'', ''Blatamtamtam''] >> >> >>> c.do_something_else("Bla") >> >> Microsoft.Scripting.Core:0:in `Bind'': Expression of type >> ''IronRuby.Builtins.Muta >> >> bleString&'' cannot be used for parameter of type >> ''IronRuby.Builtins.MutableStrin >> >> g'' of method ''System.String >> DoSomethingElse[MutableString](IronRuby.Builtins.Mut >> >> ableString ByRef)'' (ArgumentError) >> >> from Microsoft.Scripting.Core:0:in `BindCore'' >> >> from :0 >> >> >> >> >> >> >> >> >> >> On Thu, Feb 11, 2010 at 4:12 PM, Shay Friedman <shay.friedman at gmail.com> >> wrote: >> >> It returns another return value with the new ref value. >> >> >> >> For example, if you have the next c# class: >> >> public class Class1 >> >> { >> >> public string DoSomething(ref string test) >> >> { >> >> test = test + "tamtamtam"; >> >> >> >> return "return value"; >> >> } >> >> } >> >> >> >> This is the IronRuby code you can write to use it: >> >> >>> require ''c:\dev\TestApps\TestClass\TestClass\bin\Debug\TestClass.dll'' >> >> => true >> >> >>> c = Class1.new >> >> => TestClass.Class1 >> >> >>> str = "hello" >> >> => "hello" >> >> >>> result = c.do_something(str) >> >> => [''return value'', ''hellotamtamtam''] >> >> >> >> 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. >> >> >> >> Shay. >> >> -------------------------------------------------------- >> Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | >> Sela Technology Center >> Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay >> >> On Thu, Feb 11, 2010 at 3:44 PM, Michael Erasmus < >> michaelerasmus at gmail.com> wrote: >> >> Hi Everyone, >> >> >> >> I''m trying to write a IronRuby script that interops with a a .NET assembly >> written in C#. >> >> >> >> It has a class that derives from a base class in the .NET assembly. One of >> the base class protected methods looks like this: >> >> >> >> protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, >> T value) >> >> { >> >> ...... >> >> } >> >> >> >> I can''t for the life of me figure out how to call this method from IR in >> my derived class. >> >> The documentation mentions that you can call *out *parameters without >> using them as arguments, but I can''t seem to find anything about *ref * >> params. >> >> >> >> If I just try calling the method like this: >> >> >> >> OnNotifyPropertyChanged(property_name, value, value) >> >> >> >> I get this error: >> >> >> >> *Microsoft.Scripting.Core:0:in `Bind'': Expression of type >> ''IronRuby.Builtins.Muta* >> >> *bleString&'' cannot be used for parameter of type >> ''IronRuby.Builtins.MutableStrin* >> >> *g'' of method ''Void >> #base#OnNotifyPropertyChanged[MutableString](System.String, I* >> >> *ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)'' >> (Argumen* >> >> *tError)* >> >> * from Microsoft.Scripting.Core:0:in `BindCore''* >> >> * from ./dynamic_event_item.rb:22:in `method_missing''* >> >> * from :0* >> >> >> >> >> >> Am I missing something? >> >> >> >> Thanks >> >> >> >> Michael Erasmus >> >> >> >> >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> >> >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> >> >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100212/59c5692c/attachment-0001.html>
Jim Deville
2010-Feb-12 17:06 UTC
[Ironruby-core] Calling a C# method with a byref parameter
Generic type inference should work like it does in C#. I?ll get some more tests in there and get Jimmy to update the docs. JD From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ryan Riley Sent: Thursday, February 11, 2010 9:56 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Calling a C# method with a byref parameter On what types will IR be able to infer the types? Is that documented on the site and I just didn''t see it? Ryan Riley On Thu, Feb 11, 2010 at 9:55 AM, Jim Deville <jdeville at microsoft.com<mailto:jdeville at microsoft.com>> wrote: That call actually should (usually) be able to infer the type. Please file a bug on codeplex that Generic Type inference isn?t working with ByRef types. JD From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org>] On Behalf Of Shay Friedman Sent: Thursday, February 11, 2010 6:53 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] Calling a C# method with a byref parameter You should call generic methods a bit differently. The next code works: ret_val = c.method(:do_something_else).of(String).call(str) Shay. -------------------------------------------------------- Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay On Thu, Feb 11, 2010 at 4:44 PM, Michael Erasmus <michaelerasmus at gmail.com<mailto:michaelerasmus at gmail.com>> wrote: Thanks Shay. OK your code works. But my trouble seems to come in with the Generic method. When I do: public class Class1 { public string DoSomething(ref string test) { test = test + "tamtamtam"; return "return value"; } public string DoSomethingElse<T>(ref T test) { return test.ToString(); } } and then call it from IR:>>> c = TestClass::Class1.new=> TestClass.Class1>>> c.do_something("Bla")=> [''return value'', ''Blatamtamtam'']>>> c.do_something_else("Bla")Microsoft.Scripting.Core:0:in `Bind'': Expression of type ''IronRuby.Builtins.Muta bleString&'' cannot be used for parameter of type ''IronRuby.Builtins.MutableStrin g'' of method ''System.String DoSomethingElse[MutableString](IronRuby.Builtins.Mut ableString ByRef)'' (ArgumentError) from Microsoft.Scripting.Core:0:in `BindCore'' from :0 On Thu, Feb 11, 2010 at 4:12 PM, Shay Friedman <shay.friedman at gmail.com<mailto:shay.friedman at gmail.com>> wrote: It returns another return value with the new ref value. For example, if you have the next c# class: public class Class1 { public string DoSomething(ref string test) { test = test + "tamtamtam"; return "return value"; } } This is the IronRuby code you can write to use it:>>> require ''c:\dev\TestApps\TestClass\TestClass\bin\Debug\TestClass.dll''=> true>>> c = Class1.new=> TestClass.Class1>>> str = "hello"=> "hello">>> result = c.do_something(str)=> [''return value'', ''hellotamtamtam''] 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. Shay. -------------------------------------------------------- Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay On Thu, Feb 11, 2010 at 3:44 PM, Michael Erasmus <michaelerasmus at gmail.com<mailto:michaelerasmus at gmail.com>> wrote: Hi Everyone, I''m trying to write a IronRuby script that interops with a a .NET assembly written in C#. It has a class that derives from a base class in the .NET assembly. One of the base class protected methods looks like this: protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, T value) { ...... } I can''t for the life of me figure out how to call this method from IR in my derived class. The documentation mentions that you can call out parameters without using them as arguments, but I can''t seem to find anything about ref params. If I just try calling the method like this: OnNotifyPropertyChanged(property_name, value, value) I get this error: Microsoft.Scripting.Core:0:in `Bind'': Expression of type ''IronRuby.Builtins.Muta bleString&'' cannot be used for parameter of type ''IronRuby.Builtins.MutableStrin g'' of method ''Void #base#OnNotifyPropertyChanged[MutableString](System.String, I ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)'' (Argumen tError) from Microsoft.Scripting.Core:0:in `BindCore'' from ./dynamic_event_item.rb:22:in `method_missing'' from :0 Am I missing something? Thanks Michael Erasmus _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100212/744987ca/attachment-0001.html>
Shri Borde
2010-Feb-12 20:20 UTC
[Ironruby-core] Calling a C# method with a byref parameter
About documentation, the bottom of http://ironpython.net/documentation/dotnet/ has this placeholder :( Appendix - Rules for Type parameter inference while invoking generic methods TODO Jim, Dino had added tests for IronPython, and you should be able to leverage those for IronRuby http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3395 also tracks the issues with generic inference. ________________________________ From: ironruby-core-bounces at rubyforge.org [ironruby-core-bounces at rubyforge.org] on behalf of Jim Deville [jdeville at microsoft.com] Sent: Friday, February 12, 2010 9:06 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Calling a C# method with a byref parameter Generic type inference should work like it does in C#. I?ll get some more tests in there and get Jimmy to update the docs. JD From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ryan Riley Sent: Thursday, February 11, 2010 9:56 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Calling a C# method with a byref parameter On what types will IR be able to infer the types? Is that documented on the site and I just didn''t see it? Ryan Riley On Thu, Feb 11, 2010 at 9:55 AM, Jim Deville <jdeville at microsoft.com<mailto:jdeville at microsoft.com>> wrote: That call actually should (usually) be able to infer the type. Please file a bug on codeplex that Generic Type inference isn?t working with ByRef types. JD From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org>] On Behalf Of Shay Friedman Sent: Thursday, February 11, 2010 6:53 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] Calling a C# method with a byref parameter You should call generic methods a bit differently. The next code works: ret_val = c.method(:do_something_else).of(String).call(str) Shay. -------------------------------------------------------- Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay On Thu, Feb 11, 2010 at 4:44 PM, Michael Erasmus <michaelerasmus at gmail.com<mailto:michaelerasmus at gmail.com>> wrote: Thanks Shay. OK your code works. But my trouble seems to come in with the Generic method. When I do: public class Class1 { public string DoSomething(ref string test) { test = test + "tamtamtam"; return "return value"; } public string DoSomethingElse<T>(ref T test) { return test.ToString(); } } and then call it from IR:>>> c = TestClass::Class1.new=> TestClass.Class1>>> c.do_something("Bla")=> [''return value'', ''Blatamtamtam'']>>> c.do_something_else("Bla")Microsoft.Scripting.Core:0:in `Bind'': Expression of type ''IronRuby.Builtins.Muta bleString&'' cannot be used for parameter of type ''IronRuby.Builtins.MutableStrin g'' of method ''System.String DoSomethingElse[MutableString](IronRuby.Builtins.Mut ableString ByRef)'' (ArgumentError) from Microsoft.Scripting.Core:0:in `BindCore'' from :0 On Thu, Feb 11, 2010 at 4:12 PM, Shay Friedman <shay.friedman at gmail.com<mailto:shay.friedman at gmail.com>> wrote: It returns another return value with the new ref value. For example, if you have the next c# class: public class Class1 { public string DoSomething(ref string test) { test = test + "tamtamtam"; return "return value"; } } This is the IronRuby code you can write to use it:>>> require ''c:\dev\TestApps\TestClass\TestClass\bin\Debug\TestClass.dll''=> true>>> c = Class1.new=> TestClass.Class1>>> str = "hello"=> "hello">>> result = c.do_something(str)=> [''return value'', ''hellotamtamtam''] 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. Shay. -------------------------------------------------------- Shay Friedman | .NET Technologies Expert | Author of IronRuby Unleashed | Sela Technology Center Blog: http://IronShay.com | Twitter: http://twitter.com/ironshay On Thu, Feb 11, 2010 at 3:44 PM, Michael Erasmus <michaelerasmus at gmail.com<mailto:michaelerasmus at gmail.com>> wrote: Hi Everyone, I''m trying to write a IronRuby script that interops with a a .NET assembly written in C#. It has a class that derives from a base class in the .NET assembly. One of the base class protected methods looks like this: protected void OnNotifyPropertyChanged<T>(string name, ref T localmember, T value) { ...... } I can''t for the life of me figure out how to call this method from IR in my derived class. The documentation mentions that you can call out parameters without using them as arguments, but I can''t seem to find anything about ref params. If I just try calling the method like this: OnNotifyPropertyChanged(property_name, value, value) I get this error: Microsoft.Scripting.Core:0:in `Bind'': Expression of type ''IronRuby.Builtins.Muta bleString&'' cannot be used for parameter of type ''IronRuby.Builtins.MutableStrin g'' of method ''Void #base#OnNotifyPropertyChanged[MutableString](System.String, I ronRuby.Builtins.MutableString ByRef, IronRuby.Builtins.MutableString)'' (Argumen tError) from Microsoft.Scripting.Core:0:in `BindCore'' from ./dynamic_event_item.rb:22:in `method_missing'' from :0 Am I missing something? Thanks Michael Erasmus _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100212/576daabe/attachment.html>