简体   繁体   English

VS 2010 Update界面参考

[英]VS 2010 Update interface references

Is there any way in VS 2010 to auto update classes referencing an Interface? VS 2010中有什么方法可以自动更新引用接口的类? Say i add a parameter to Export, is there any function that will update all my referencing interfaces? 说我在导出中添加了一个参数,是否有任何功能可以更新我所有的引用接口?

public interface IStateExporter
{
    void Export();
}

to

public interface IStateExporter
{
    void Export(string path);
}

The Refactor context menu lets you remove and re-order parameters and will update all implementations of the interface. 重构上下文菜单使您可以删除和重新排序参数,并将更新该接口的所有实现。 But, the best VS2010 can offer when adding a parameter is the ability to automatically implement the updated member with a new method that throws NotImplementedException. 但是,添加参数时,VS2010最好的功能就是能够使用抛出NotImplementedException的新方法自动实现更新的成员。

I know CodeRush/Refactor Pro from DevExpress has a function that walks you through adding/changing parameters and visiting each implementer to let you add the parameter. 我知道DevExpress的CodeRush / Refactor Pro具有一个功能,可引导您完成添加/更改参数并访问每个实现者以添加参数。 I imagine ReSharper has the same feature, but I don't know for sure. 我认为ReSharper具有相同的功能,但我不确定。

Not in the way that you are thinking if I understand you correctly. 如果您对我的理解正确,那将不是您的想法。

What you can do is go to the inheritance declaration, and use the auto implement feature to save a little time. 您可以做的是转到继承声明,并使用自动实施功能节省一些时间。

So for example, put the cursor over IStateExporter in the line 因此,例如,将光标放在该行的IStateExporter上方

public class ContreteStateExporter : IStateExporter

and hit CTRL + . 然后按CTRL +。 (Control plus period) and choose to implement the interface. (控件加句点),然后选择实现该界面。 Then, you can copy paste the code from the previous method. 然后,您可以复制粘贴以前方法中的代码。 Still, extremely messy, but I suppose it would save you a little time. 仍然非常混乱,但是我想这可以为您节省一些时间。

Went out searching some more, Resharper does exactly what I am asking. 出去搜索更多,Resharper完全按照我的要求去做。 Not only from the interface but you can also change the implementationa dn ask it to update the interface and all references. 不仅从接口,而且您还可以更改实现,也可以要求其更新接口和所有引用。

Resharper worked perfect. Resharper运作完美。

Added my new param to the implementation, and little icon popped up, asked me if i would like to update the interface and the other implementations, clicked yes. 将我的新参数添加到实现中,然后弹出小图标,问我是否要更新界面和其他实现,请单击“是”。 Bam, all of the m and the interface(same signature) all have the param now. Bam,所有m和接口(相同签名)现在都具有参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM