If you really just want a way to get it done that way is via Reflection.Emit. Either you can do it all via RefEmit and ignore creating classes from Python or you can try and cooperate w/ IronPython and extend a Python class so it has attributes. The former I'll leave to the RefEmit documentation (or classes like NewTypeMaker in the IronPython code base). For the latter the most important thing to understand is what happens when you do:
class xyz(object): pass in IronPython. We create a new type, IronPython.Runtime.NewTypes.System.Object_# where # is an ever-increasing number for each class created. We override all the virtual methods and add a new ctor: Object_#(UserType type); The argument there becomes the __class__ field which the user can change at runtime. Therefore what you'd want to do is first define a class in Python, create an instance of it, then call .GetType() to get its type. From there you could derive from that type adding any attributes you wanted. Then you could create instances of it by calling the new type and passing in a type object. You can probably simply that latter part by poking around at UserType (in v1.x) and DynamicType (in v2.x) so that you can easily create the type. Alternately when you create the new subtype you can have it always call the base ctor w/ your previously created UserType instance. That's probably no small amount of work but that's how you could do it. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Benjamin West Sent: Wednesday, May 23, 2007 3:40 PM To: Discussion of IronPython Subject: Re: [IronPython] how to apply guid On 5/23/07, Dino Viehland <[EMAIL PROTECTED]> wrote: > We don't yet support defining attributes from Python. It's a common feature > request. > > For that you'll need to go to a static language like C# :(. > > I'm not so interested in defining attributes as applying them. My C# book says attributes are just metadata, inspectable by using reflection. It also suggests that you can programmatically modify metadata. Is it possible to use reflection to apply these attributes as necessary? I realize that it would be a bit ugly, but I'm especially interested in doing COM interop stuff with IronPython. Also, I'm having a bit of trouble figuring out how to strongname an IronPython assembly created using pyc.py. Is there any way to do this? I'm not necessarily looking for syntactic sugar using decorators or anything... just looking for a way to get it done. The sugar will come later. -Ben _______________________________________________ users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
