2008-12-11 32 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

相关问题