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
2008-12-11 23:43:50
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
2010-08-22 23:41:08