Ivan Porto Carrero
2009-Apr-28 17:38 UTC
[Ironruby-core] [IronPython] Telling .NET classes from Python objects
+1 for this question only I need it to implement different binding strategies in IronMVC. IronRuby in Action (http://manning.com/carrero) Winston Churchill<http://www.brainyquote.com/quotes/authors/w/winston_churchill.html> - "The best argument against democracy is a five-minute conversation with the average voter." On Tue, Apr 28, 2009 at 7:35 PM, Michael Foord <fuzzyman at voidspace.org.uk>wrote:> Hello guys, > > I''m continuing my work on generating pi files for the Wing IDE. Actually > everything I encounter will be a .NET type, but in general what is the best > way of telling if an object is a .NET type or a Python type? > > Obviously for the primitives it is a moot point - but I''m talking about > user defined classes. > > Michael > > -- > http://www.ironpythoninaction.com/ > http://www.voidspace.org.uk/blog > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090428/2aed2a21/attachment.html>
Tomas Matousek
2009-Apr-28 18:04 UTC
[Ironruby-core] [IronPython] Telling .NET classes from Python objects
Would you consider Bignum to be a .NET type or Ruby type? Tomas From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland Sent: Tuesday, April 28, 2009 10:41 AM To: Discussion of IronPython; ironruby-core Subject: Re: [IronPython] Telling .NET classes from Python objects Check to see if the object implements IPythonObject. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ivan Porto Carrero Sent: Tuesday, April 28, 2009 10:38 AM To: Discussion of IronPython; ironruby-core Subject: Re: [IronPython] Telling .NET classes from Python objects +1 for this question only I need it to implement different binding strategies in IronMVC. IronRuby in Action (http://manning.com/carrero) Winston Churchill<http://www.brainyquote.com/quotes/authors/w/winston_churchill.html> - "The best argument against democracy is a five-minute conversation with the average voter." On Tue, Apr 28, 2009 at 7:35 PM, Michael Foord <fuzzyman at voidspace.org.uk<mailto:fuzzyman at voidspace.org.uk>> wrote: Hello guys, I''m continuing my work on generating pi files for the Wing IDE. Actually everything I encounter will be a .NET type, but in general what is the best way of telling if an object is a .NET type or a Python type? Obviously for the primitives it is a moot point - but I''m talking about user defined classes. Michael -- http://www.ironpythoninaction.com/ http://www.voidspace.org.uk/blog _______________________________________________ Users mailing list Users at lists.ironpython.com<mailto:Users at lists.ironpython.com> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090428/79f96ffe/attachment.html>
Michael Letterle
2009-Apr-28 18:10 UTC
[Ironruby-core] [IronPython] Telling .NET classes from Python objects
Class#to_clr_type? Returns nil for custom Ruby objects... depends on what you''re looking for... On Tue, Apr 28, 2009 at 1:38 PM, Ivan Porto Carrero <ivan at flanders.co.nz> wrote:> +1 for this question only I need it to implement different binding > strategies in IronMVC. > > IronRuby in Action (http://manning.com/carrero) > > Winston Churchill ?- "The best argument against democracy is a five-minute > conversation with the average voter." > > On Tue, Apr 28, 2009 at 7:35 PM, Michael Foord <fuzzyman at voidspace.org.uk> > wrote: >> >> Hello guys, >> >> I''m continuing my work on generating pi files for the Wing IDE. Actually >> everything I encounter will be a .NET type, but in general what is the best >> way of telling if an object is a .NET type or a Python type? >> >> Obviously for the primitives it is a moot point - but I''m talking about >> user defined classes. >> >> Michael >> >> -- >> http://www.ironpythoninaction.com/ >> http://www.voidspace.org.uk/blog >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-- Michael Letterle IronRuby MVP http://blog.prokrams.com
Tomas Matousek
2009-Apr-28 18:45 UTC
[Ironruby-core] [IronPython] Telling .NET classes from Python objects
I would recommend not to rely on whether an object is Ruby object or .NET object if possible. You might be surprised to get a COM object, a Python object, DLR expand, etc. if you do so. Use rather respond_to?, include? to ask for specific methods/protocols. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Michael Letterle Sent: Tuesday, April 28, 2009 11:10 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] [IronPython] Telling .NET classes from Python objects Class#to_clr_type? Returns nil for custom Ruby objects... depends on what you''re looking for... On Tue, Apr 28, 2009 at 1:38 PM, Ivan Porto Carrero <ivan at flanders.co.nz> wrote:> +1 for this question only I need it to implement different binding > strategies in IronMVC. > > IronRuby in Action (http://manning.com/carrero) > > Winston Churchill ?- "The best argument against democracy is a five-minute > conversation with the average voter." > > On Tue, Apr 28, 2009 at 7:35 PM, Michael Foord <fuzzyman at voidspace.org.uk> > wrote: >> >> Hello guys, >> >> I''m continuing my work on generating pi files for the Wing IDE. Actually >> everything I encounter will be a .NET type, but in general what is the best >> way of telling if an object is a .NET type or a Python type? >> >> Obviously for the primitives it is a moot point - but I''m talking about >> user defined classes. >> >> Michael >> >> -- >> http://www.ironpythoninaction.com/ >> http://www.voidspace.org.uk/blog >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-- Michael Letterle IronRuby MVP http://blog.prokrams.com _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Ivan Porto Carrero
2009-Apr-28 19:58 UTC
[Ironruby-core] [IronPython] Telling .NET classes from Python objects
Bignum I''d consider to be a primitive :) but it would be a ruby type I''m thinking about models / DTO''s etc. It''s for a databinding context where you get a list of strings that then need to populate an object. And to pick the right conversion mechanisms I need a different strategy for a DLR type as for a CLR type. On Tue, Apr 28, 2009 at 8:04 PM, Tomas Matousek < Tomas.Matousek at microsoft.com> wrote:> Would you consider Bignum to be a .NET type or Ruby type? > > > > Tomas > > > > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Dino Viehland > *Sent:* Tuesday, April 28, 2009 10:41 AM > *To:* Discussion of IronPython; ironruby-core > *Subject:* Re: [IronPython] Telling .NET classes from Python objects > > > > Check to see if the object implements IPythonObject. > > > > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Ivan Porto Carrero > *Sent:* Tuesday, April 28, 2009 10:38 AM > *To:* Discussion of IronPython; ironruby-core > *Subject:* Re: [IronPython] Telling .NET classes from Python objects > > > > +1 for this question only I need it to implement different binding > strategies in IronMVC. > > > > > IronRuby in Action (http://manning.com/carrero) > > Winston Churchill<http://www.brainyquote.com/quotes/authors/w/winston_churchill.html> - "The best argument against democracy is a five-minute conversation with > the average voter." > > On Tue, Apr 28, 2009 at 7:35 PM, Michael Foord <fuzzyman at voidspace.org.uk> > wrote: > > Hello guys, > > I''m continuing my work on generating pi files for the Wing IDE. Actually > everything I encounter will be a .NET type, but in general what is the best > way of telling if an object is a .NET type or a Python type? > > Obviously for the primitives it is a moot point - but I''m talking about > user defined classes. > > Michael > > -- > http://www.ironpythoninaction.com/ > http://www.voidspace.org.uk/blog > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > 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/20090428/6ffb7cd0/attachment.html>
Curt Hagenlocher
2009-Apr-29 03:51 UTC
[Ironruby-core] [IronPython] Telling .NET classes from Python objects
I''d probably pick IDynamicMetaObjectProvider as the signifier of a dynamic type. Ruby and Python types that don''t implement this interface aren''t "as dynamic" as types that do -- even built-in ones -- because they won''t support dynamic binding from other languages. And all user-defined types would implement it. As a bonus, you can get a list of member names directly from the MetaObject returned by the IDMOP using something like this: var idmop = obj as IDynamicMetaObjectProvider; if (idmop != null) { var expr = System.Linq.Expressions.Parameter(typeof(object)); // The DLR version, not the LINQv1 version! var dmo = idmop.GetMetaObject(expr); IEnumerable<string> names = dmo.GetDynamicMemberNames(); } You could then create simple binders and use CallSites directly to actually get and set the data members yourself -- and the result should support any DLR language and not just Python or Ruby. Disclaimer: I haven''t tested this, but it should work -- it''s the basis for C# interop in .NET 4.0, after all. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ivan Porto Carrero Sent: Tuesday, April 28, 2009 12:59 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] [IronPython] Telling .NET classes from Python objects Bignum I''d consider to be a primitive :) but it would be a ruby type I''m thinking about models / DTO''s etc. It''s for a databinding context where you get a list of strings that then need to populate an object. And to pick the right conversion mechanisms I need a different strategy for a DLR type as for a CLR type. On Tue, Apr 28, 2009 at 8:04 PM, Tomas Matousek <Tomas.Matousek at microsoft.com<mailto:Tomas.Matousek at microsoft.com>> wrote: Would you consider Bignum to be a .NET type or Ruby type? Tomas From: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com> [mailto:users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com>] On Behalf Of Dino Viehland Sent: Tuesday, April 28, 2009 10:41 AM To: Discussion of IronPython; ironruby-core Subject: Re: [IronPython] Telling .NET classes from Python objects Check to see if the object implements IPythonObject. From: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com> [mailto:users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com>] On Behalf Of Ivan Porto Carrero Sent: Tuesday, April 28, 2009 10:38 AM To: Discussion of IronPython; ironruby-core Subject: Re: [IronPython] Telling .NET classes from Python objects +1 for this question only I need it to implement different binding strategies in IronMVC. IronRuby in Action (http://manning.com/carrero) Winston Churchill<http://www.brainyquote.com/quotes/authors/w/winston_churchill.html> - "The best argument against democracy is a five-minute conversation with the average voter." On Tue, Apr 28, 2009 at 7:35 PM, Michael Foord <fuzzyman at voidspace.org.uk<mailto:fuzzyman at voidspace.org.uk>> wrote: Hello guys, I''m continuing my work on generating pi files for the Wing IDE. Actually everything I encounter will be a .NET type, but in general what is the best way of telling if an object is a .NET type or a Python type? Obviously for the primitives it is a moot point - but I''m talking about user defined classes. Michael -- http://www.ironpythoninaction.com/ http://www.voidspace.org.uk/blog _______________________________________________ Users mailing list Users at lists.ironpython.com<mailto:Users at lists.ironpython.com> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ 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/20090428/e0da1cfd/attachment.html>