1

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 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

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?
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.