如果在 Visual Studio 的选项页面 调试 | 常规 上选择了 启用属性评估和其他隐式函数调用 ,则导航到实现也适用于持有接口类型的属性。
interface IMyInterface { public void Print(); }
class One : IMyInterface
{
public void Print() => Console.WriteLine("One");
}
class Two : IMyInterface
{
public void Print() => Console.WriteLine("Two");
}
class Test
{
void Test1() => MyTest(new One());
void Test2() => MyTest(new Two());
void MyTest(IMyInterface input)
{
// 'Go to Declaration' on 'Print()' will navigate to
// its implementation in 'One' or in 'Two'
// depending on the debugger context.
input.Print();
}
}