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.<strong>Dynamic</strong> for the 2.6 release.)<br>
<br>
<div class="gmail_quote">On Tue, Apr 14, 2009 at 8:31 AM, Alex News <span dir="ltr"><<a href="mailto:anleewxs@gmail.com">anleewxs@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Much appreciated, I will give that a try. In what namespace is<br>DynamicObject declared? (I assume the required assemblies are already<br>
referenced if I'm pulling in IronPython).<br><br>Thanks again,<br><font color="#888888">Alex<br></font>
<div>
<div></div>
<div class="h5"><br><br>On Tue, Apr 14, 2009 at 11:16 AM, Dino Viehland <<a href="mailto:dinov@microsoft.com">dinov@microsoft.com</a>> wrote:<br>> For kwargs you need to decorate the function w/ a ParamDictionary attribute such as:<br>
><br>> public void __init__(CodeContext/*!*/ context, object o, [ParamDictionary] IAttributesCollection kwArgs)<br>><br>> For __getattr__ IronPython will recognize a special name "GetBoundMember" method such as:<br>
><br>> using System;<br>> using System.Runtime.CompilerServices;<br>><br>> public class Foo {<br>> [SpecialName]<br>> public object GetBoundMember (string name) {<br>> return name;<br>
> }<br>> }<br>><br>><br>> 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#, <a href="http://vb.net/" target="_blank">VB.NET</a>, IronRuby, etc...).<br>
><br>><br>>> -----Original Message-----<br>>> From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-">users-</a><br>>> <a href="mailto:bounces@lists.ironpython.com">bounces@lists.ironpython.com</a>] On Behalf Of Alex News<br>
>> Sent: Tuesday, April 14, 2009 7:32 AM<br>>> To: <a href="mailto:users@lists.ironpython.com">users@lists.ironpython.com</a><br>>> Subject: [IronPython] **kwargs and __getattr__ handling in csharp<br>>> functions and classes?<br>
>><br>>> I would like to write some functions and classes in csharp that<br>>> interact nicely python. I would like to write a function that can<br>>> respond to keyword arguments, and a class that can dynamically resolve<br>
>> __getattr__.<br>>><br>>> For the function I tried creating a function that takes a<br>>> IronPython.Runtime.PythonDictionary, but did not work. For a class I<br>>> tried creating a function that have a method __getattr__, but that<br>
>> failed too.<br>>><br>>> I see there is a IronPython.Runtime.PythonFunction and some other<br>>> interesting classes in the Runtime, but it is not apparent exactly how<br>>> I could use them.<br>
>><br>>> I can, luckily, fudge much of what I want to do by creating small<br>>> python classes and functions in python to proxy the values to<br>>> underlying csharp classes. However thing would be cleaner if I could<br>
>> do it directly in csharp.<br>>><br>>> Thanks in advance for any suggestions.<br>>><br>>> Alex<br>>> _______________________________________________<br>>> Users mailing list<br>
>> <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>>> <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
><br>> _______________________________________________<br>> Users mailing list<br>> <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>> <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</div></div></blockquote></div><br>