可以使用Visual Studio提供的代码生成功能来实现这一目的。下面是示例代码:
public interface IMyInterface { void MyMethod(); }
@inject IMyInterface MyInterfaceInstance
在页面上右键点击接口实例,并选择“Quick Actions and Refactorings”(快速操作和重构):
选择“Generate Method”(生成方法),输入方法名称并点击确定:
生成的方法将会自动添加到接口中,并且你可以使用F12来跳转到其定义位置。