[英]IronPython implementing interface Properties
我正在實現在IronPython中用C#定義的接口,但不能使屬性實現工作:
C#
interface IInterface
{
Dictionary<string, element> Elements { get; }
}
蟒蛇:
class Implementor(IInterface):
def __init__(self):
self.elements = Dictionary[str, element]()
def get_Elements(self):
return self.elements
調用get_Elements時,我得到以下異常:
Elements的預期屬性,但找到了Dictionary [str,element]
我做錯了什么?
謝謝!
使用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#中,屬性工作正常)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.