2
由于IronPython不支持属性,我想知道是否有另一种方法来装饰IronPython类的属性,也许用反射?如何向IronPython中定义的方法和类型添加属性?
由于IronPython不支持属性,我想知道是否有另一种方法来装饰IronPython类的属性,也许用反射?如何向IronPython中定义的方法和类型添加属性?
尽管丑陋且有时不切实际,但解决方法是在C#中创建存根类并使用属性装饰它,并从IronPython中派生出来。
我不确定这是你在找什么,但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)
我不确定它是否能在类上工作。
在IryonPython 2.6.2和2.7 Beta 2中,我没有找到该clrtype模块。你能给我一个提示吗? – MarkusSchaber 2011-03-18 11:58:39