2008-12-11 5 views

ответ

2

Одним из, хотя и уродливым, а иногда и непрактичным, обходным путем является создание класса-заглушки на C# и украшение его атрибутами и извлечение из него в IronPython.

1

Я не уверен, что это то, что вы ищете, но clrtype позволяет использовать атрибут.

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) 

Я не уверен, работает ли он на занятиях.

+4

В IryonPython 2.6.2 и 2.7 Beta 2 я не нашел этот модуль clrtype. Можете ли вы дать мне подсказку, где она? – MarkusSchaber 2011-03-18 11:58:39