[IronPython] How to implement in C# ironpython extension?

Dino Viehland dinov at exchange.microsoft.com
Tue Nov 28 11:34:50 PST 2006


__getitem__ and __setitem__ can be implemented by implementing an indexer in C#.  These will automatically be transformed.

To implement __getattribute__ / __setattr__ you can implement ICustomAttributes and intercept all attribute access.  You'll need to fall back to the type to get the default behavior, e.g. something like (see SystemState.cs for an approximate answer):

Return Ops.GetDynamicType(this).TryGetAttr(context, this, name, out value);

There's no way to implement just __getattr__, only __getattribute__.

Other special methods you can implement by name or by applying PythonName("__foo__") to the method. There are certain interfaces we'll recognize and transform for you automatically (IEnumerator -> next, ToString -> __str__, ICodeFormattable -> __repr__, IDescriptor -> __get__, and ICallable -> __call__).

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Andrew
Sent: Tuesday, November 21, 2006 10:36 AM
To: users at lists.ironpython.com
Subject: Re: [IronPython] How to implement in C# ironpython extension?

Thank you for answer! I should to be more acurate.
How to implement in C# extension special methods:
__getitem__, __setitem__, __getattr__, __setattr__ and other special methods?

Thanks.




More information about the users mailing list