[IronPython] **kwargs and __getattr__ handling in csharp functions and classes?

Curt Hagenlocher curt at hagenlocher.org
Tue Apr 14 18:12:09 CEST 2009


In current versions of IronPython, DynamicObject is in
Microsoft.Scripting.Core as Microsoft.Scripting.DynamicObject.  In .NET 4.0
System.Core, the same class will be called System.Dynamic.DynamicObject.  (I
just noticed this naming discrepancy today, and I think we should probably
move it to at least Microsoft.*Dynamic* for the 2.6 release.)

On Tue, Apr 14, 2009 at 8:31 AM, Alex News <anleewxs at gmail.com> wrote:

> Much appreciated, I will give that a try.  In what namespace is
> DynamicObject declared?  (I assume the required assemblies are already
> referenced if I'm pulling in IronPython).
>
> Thanks again,
> Alex
>
>
> On Tue, Apr 14, 2009 at 11:16 AM, Dino Viehland <dinov at microsoft.com>
> wrote:
> > For kwargs you need to decorate the function w/ a ParamDictionary
> attribute such as:
> >
> > public void __init__(CodeContext/*!*/ context, object o,
> [ParamDictionary] IAttributesCollection kwArgs)
> >
> > For __getattr__ IronPython will recognize a special name "GetBoundMember"
> method such as:
> >
> > using System;
> > using System.Runtime.CompilerServices;
> >
> > public class Foo {
> >    [SpecialName]
> >    public object GetBoundMember (string name) {
> >        return name;
> >    }
> > }
> >
> >
> > You can also do "GetCustomMember" which is like __getattribute__.  But
> for this one what you really want to do is inherit directly from the
> DynamicObject class and override TryGetMember.  Then it'll work not only w/
> Python but w/ other DLR based languages as well (e.g. C#, VB.NET<http://vb.net/>,
> IronRuby, etc...).
> >
> >
> >> -----Original Message-----
> >> From: users-bounces at lists.ironpython.com [mailto:users-
> >> bounces at lists.ironpython.com] On Behalf Of Alex News
> >> Sent: Tuesday, April 14, 2009 7:32 AM
> >> To: users at lists.ironpython.com
> >> Subject: [IronPython] **kwargs and __getattr__ handling in csharp
> >> functions and classes?
> >>
> >> I would like to write some functions and classes in csharp that
> >> interact nicely python.  I would like to write a function that can
> >> respond to keyword arguments, and a class that can dynamically resolve
> >> __getattr__.
> >>
> >> For the function I tried creating a function that takes a
> >> IronPython.Runtime.PythonDictionary, but did not work.  For a class I
> >> tried creating a function that have a method __getattr__, but that
> >> failed too.
> >>
> >> I see there is a IronPython.Runtime.PythonFunction and some other
> >> interesting classes in the Runtime, but it is not apparent exactly how
> >> I could use them.
> >>
> >> I can, luckily, fudge much of what I want to do by creating small
> >> python classes and functions in python to proxy the values to
> >> underlying csharp classes.  However thing would be cleaner if I could
> >> do it directly in csharp.
> >>
> >> Thanks in advance for any suggestions.
> >>
> >> Alex
> >> _______________________________________________
> >> Users mailing list
> >> Users at lists.ironpython.com
> >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> _______________________________________________
> 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://mail.python.org/pipermail/ironpython-users/attachments/20090414/aeefa2d8/attachment.html>


More information about the Ironpython-users mailing list