【发布时间】:2011-07-16 10:26:31
【问题描述】:
我编写了一个嵌套类,用作属性的包。此类用作我命名为Properties 的属性。我想通过接口扩展属性的数量。
我写了这个例子:
public interface IFirst {
int asd { get; set; }
}
public interface ISecond {
int zxc { get; set; }
}
public class MyClass {
public class PropertyClass : IFirst {
public int asd {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
}
public PropertyClass Properties;
}
public class MyNextClass : MyClass {
public class PropertyClass : MyClass.PropertyClass, ISecond {
public int zxc {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
}
public void test() {
Properties.zxc = 5; // Here is problem
}
}
但在这种情况下,我无法读取/写入新属性 zxc。
我认为因为这仍然是从父类读取 Properties 类型 - MyClass.PropertyClass 而不是 MyNextClass.PropertyClass。
我想在不创建新属性或隐藏现有属性的情况下扩展它。
你有什么建议吗?
【问题讨论】:
标签: c# inheritance interface properties nested-class