views:

185

answers:

2

Since IronPython doesn't support attributes I am wondering if there is another way to decorate IronPython classes with attributes, perhaps with reflection?

+1  A: 

One, albeit ugly and sometimes impractical, workaround is to create a stub class in C# and decorate it with attributes and derive from that in IronPython.

srivatsn
A: 

I'm not sure if this is what you are looking for, but clrtype allows you to use attribute.

import clr
import clrtype
from System.Runtime.InteropServices import DllImportAttribute
import System

class PInvoke(object):

    __metaclass__ = clrtype.ClrClass
    DllImport = clrtype.attribute(DllImportAttribute)

    @staticmethod
    @DllImport("user32.dll")
    @clrtype.accepts(System.UInt32)
    @clrtype.returns(System.Boolean)
    def MessageBeep(beepType): raise RuntimeError("Something went wrong.")

PInvoke.MessageBeep(0)

I'm not sure if it works on classes though.

jcao219