在 IronPython 中调用基数 属性 或覆盖 属性

Call base property of overridden property in IronPython

我在 C# 中有一个 class,带有一个简单的 属性,它是虚拟的

public class Foo
{
    public virtual string SomeProperty {get;set;}
}

在 IronPython 中,我尝试覆盖这样的属性并将其称为基础 class:

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: cannot set slot at IronPython.Runtime.Types.PythonType.SetMember(CodeContext context, Object instance, String name, Object value) at CallSite.Target(Closure , CallSite , Object , Object ) ...

我也尝试将其实现为 super(Bar,self).set_SomeProperty(value),但这给出了 set_SomeProperty 不存在的错误。

请尝试像这样实现您的 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。希望这有帮助。