我正在使用IoC来定义我的继承类中的一些行为。我有一个属性如何在更高级别中使用重写的属性值?
protected virtual bool UsesThing { get { return true; } }
在我的顶级类。
在我的继承类我有
protected override bool UsesThing { get { return false; } }
我用我的顶层类物业
,并且它使用的顶级价值。有没有办法让它使用继承的值?我认为这就是虚拟应该做的。
代码示例:
using System;
public class Program
{
public static void Main()
{
B b = new B();
b.PrintThing();
//I want this to print the value for B
}
public class A
{
protected virtual bool Enabled
{
get
{
return true;
}
}
public void PrintThing()
{
Console.WriteLine(this.Enabled.ToString());
}
}
public class B : A
{
protected override bool Enabled
{
get
{
return false;
}
}
}
}
Here's a Dot Net Fiddle demonstrating my problem
你可以发布[MCVE](http://stackoverflow.com/help/mcve)吗? – dcastro 2014-10-27 17:53:28
当然,lemme杜松子酒的小提琴 – Codeman 2014-10-27 17:54:29
@dcastro我添加了一个:) – Codeman 2014-10-27 17:59:05