オーバーライドされる仮想メソッドがある単純なクラス階層があります。しかし、特定のコールサイトでは、仮想メソッドではなく、このメソッドの基本クラス バージョンを呼び出したいと考えています。
例えば:
public class A {
public virtual void Foo() {...}
}
public class B : A {
public override void Foo() {...}
}
public class Program {
public void SomeMethod()
{
...
// ListofA is type IEnumerable<A>
foreach (var item in ListofA)
{
// I want this to call A.Foo(), rather than B.Foo()
// But everything I've tried, which has really just been casting, has resulted in B.Foo()
item.Foo();
}
}
}