Since IronPython doesn't support attributes I am wondering if there is another way to decorate IronPython classes with attributes, perhaps with reflection?
2 Answers
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.
2 Comments
MarkusSchaber
In IryonPython 2.6.2 and 2.7 Beta 2, I don't find that clrtype module. Can you give me a hint where it is?
Dmitry Dronov
Can you help me please convert for example this:
[DllImport("user32.dll")] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo) To IronPython that i can understand how it work?