比方说,我有一个类,它有一个属性隐藏它的基本属性和嵌套类在这个类内。是否有可能访问基地隐藏 * 虚拟 *属性来自嵌套类?从嵌套类访问外部类隐藏的基本属性
下面是一个例子:
class BaseClass
{
protected virtual String SomeProperty {get; set;}
}
class Inherited : BaseClass
{
protected new String SomeProperty {get; set;}
class Nested
{
Inherited parent;
public Nested(Inherited parent)
{
this.parent = parent;
}
public void SomeMethod()
{
//How do I access the SomeProperty which belongs to the BaseClass?
}
}
}
,我能想到的唯一解决方案是一个私有方法添加到继承的类返回base.SomeProperty
有没有更好的解决办法?
你在哪里试图访问它,为什么你隐藏了财产的第一个地方? –
我试图从嵌套类的方法访问它。我隐藏了基本属性,因为新属性提供了比基本属性更多的功能,我不想拥有两个属性。 – Giorgi