在 Visual Studio 中有效传播界面更改
当我深入研究解耦和依赖注入的世界时,我发现自己正在编写越来越多的接口。我尽力创建接口,并确切地知道如何使用它们,但总有一种情况是我最终实现了接口,然后更改了它的使用方式。
我已经习惯了VS的自动重构能力。但我发现它不支持将接口更改自动传播到实现类。有没有办法自动执行此操作,以便在编译错误消失之前我不会复制和粘贴?
As I delve into the world of decoupling and dependency injection, I'm finding myself writing more and more interfaces. I try my best to create interfaces knowing exactly how I'm going to use them, but there's always the case that I end up implementing the interface and then changing how it's used.
I've become accustomed to VS' automatic refactoring ability. But I've found that it doesn't support propagating interface changes automatically to the implementing classes. Is there a way to do this automatically so I'm not copying and pasting until my compile errors go away?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 Visual Studio 或任何其他工具无法“知道”实现应该是什么,因此实现它的责任就落在您(开发人员)身上。
如果您更改接口定义,那么在您实现更改之前编译会失败,这是一件好事。
Since Visual Studio, or any other tool can't "know" what the implementation should be, it falls to you, the developer to implement it.
If you change an interface definition, it is a good thing that compilation fails until you have implemented the change.
想回来回答这个问题:
如果您想更改接口方法名称,如果您从实例化类更改它,Visual Studio 将为您提供将其传播到接口的选项(以及整个您的所有其他调用)代码,正常)。如果更改接口定义中的方法名称,则更改不会传播到实例化类。
Wanted to come back and answer this question:
If you want to change an interface method name, if you change it from the instantiating class, Visual Studio will give you the option to propagate it to the interface (as well as all other calls throughout your code, as normal). If you change the method name in the interface definition, the change will not propagate to the instantiating classes.