我在C#中有一个具有虚拟
的简单属性的类public class Foo
{
public virtual string SomeProperty {get;set;}
}
在IronPython中,我尝试覆盖这样的属性并将其称为基类:
class Bar(Foo):
def get_SomeProperty(self):
# do something special and then:
return super(Bar,self).SomeProperty
def set_SomeProperty(self,value):
# do something special and then:
super(Bar,self).SomeProperty = value
它出现以下错误:
System.MissingMemberException:无法设置插槽位置 IronPython.Runtime.Types.PythonType.SetMember(CodeContext context, 对象实例,字符串名称,对象值) CallSite.Target(Closure,CallSite,Object,Object) ...
我也尝试将其实现为super(Bar,self).set_SomeProperty(value)
,但这会产生set_SomeProperty不存在的错误。
答案 0 :(得分:1)
请尝试像这样实现你的getter / setter:
class Bar(Foo):
@property
def SomeProperty(self):
# do something special and then:
return super(Bar,self).SomeProperty
@SomeProperty.setter
def SomeProperty(self,value):
# do something special and then:
super(Bar,self).SomeProperty = value
要使其成为getter / setter,您应该使用@property
和@<MEMBER>.setter
。希望这会有所帮助。