IronPython实现接口属性

时间:2012-03-21 15:55:50

标签: c# properties ironpython

我正在实现在IronPython中用C#定义的接口,但无法制作 物业实施工作:

C#

interface IInterface
 {
  Dictionary<string, element> Elements { get; }
 }

的Python:

class Implementor(IInterface):
    def __init__(self):
        self.elements = Dictionary[str, element]()

    def get_Elements(self):
        return self.elements

调用get_Elements时,我得到以下异常:

  

Elements的预期属性,但找到了Dictionary [str,element]

我做错了什么?

谢谢!

1 个答案:

答案 0 :(得分:1)

使用def Implementor(),您要定义一个方法,而不是一个类 正确的代码是class Implementor()

class Implementor(IInterface):
    def __init__(self):
        self.elements = Dictionary[str, element]()

    def get_Elements(self):
        return self.elements

这段代码在我的测试中工作正常(我从Python范围内将一个Implementor实例变量提取到C#中,属性工作正常)。

相关问题