在Visual Studio 2010中进行重构/封装 [英] Refactor/Encapsulate in Visual Studio 2010

查看:99
本文介绍了在Visual Studio 2010中进行重构/封装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图找到一种方法来比Visual Studio中的默认方法更多地进行快捷方式重构/封装.例如,现在输入以下内容:

Hi,

I am trying to find a way to shortcut refactor/encapsulate more than the default in Visual Studio. For example, now if I type this:

<pre lang="cs"><br />
private string serverSMTP = string.Empty;<br />
</pre>


然后我可以右键单击,选择重构",然后选择封装"并获得此信息:


then I can right click, choose Refactor, then Choose Encapsulate and get this:

<br />
<pre lang="cs">private string serverSMTP = string.Empty;<br />
<br />
public string ServerSMTP<br />
{<br />
    get { return serverSMTP; }<br />
    set { serverSMTP = value; }<br />
}</pre><br />



我希望能够对其进行自定义以代替执行此操作,是否有任何方法可以完成此操作?扩展它是否有捷径可走?像Ctrl R,E?



I''d like to be able to customize it to do this instead, is there any way to accomplish this? And expanding that is there a way to shortcut it? like Ctrl R, E?

<br />
<pre lang="cs">private string serverSMTP = string.Empty;<br />
public string ServerSMTP<br />
{<br />
    get { return serverSMTP; }<br />
    set<br />
    {<br />
        if (value != serverSMTP)<br />
        {<br />
            serverSMTP = value;<br />
            RaisePropertyChanged("ServerSMTP");<br />
        }<br />
    }<br />
}</pre><br />
<br />

推荐答案

好问题.

我读过某个地方,微软尚未计划使用Visual Studio代码重构引擎进行自定义.找到相关代码片段所在的目录("[Visual Studio路径] \ VC#\ Snippets \ 1033 \"),仅搜索"* .snippet"-您将找到子目录"Refactoring".您可以使用它,但是我在Microsoft文档中的某个地方读到了不建议这样做的信息.您仍然可以尝试这些东西,因为您始终可以备份和还原它.相比之下,我自定义了"Visual C#"代码片段(不使用Visual Studio IDE,因为这对我来说太繁琐,但直接使用),并且能够添加自己的代码片段并改进现有的代码片段.我不确定是否可以添加重构代码段;可能不是因为它们应该由更复杂的代码来支持.

另一种方法是使用节点"Other Project Types" =>中的项目模板从头开始创建Visual Studio 插件. 可扩展性".

您可以尝试使用诸如 Visual Assist X CodeRush ReSharper 之类的商业化加载项,它们都应该支持代码重构.您可以在Wikipedia中找到这些产品.

—SA
Good question.

I''ve read somewhere that customization using Visual Studio code re-factoring engine is planned by Microsoft by not yet delivered. Locate directory where the related snippets are ("[Visual Studio path]\VC#\Snippets\1033\"), just search for "*.snippet" — you will find the sub-directory "Refactoring". You can play with that, but I''re read somewhere in Microsoft documentation that it''s not recommended. Still you could experiment this this stuff, as you can always backup and restore it. In contrast, I customized my "Visual C#" snippets (not using Visual Studio IDE, as it''s too tedious to me, but directly) and was able to add my own snippets and improve existing ones. I''m not sure if it''s possible to add re-factoring snippets; probably not because they should be backed by much more complex code.

Another approach is creation of Visual Studio add-in from scratch, using project templates from the node "Other Project Types" => "Extensibility".

You can try available commercial add-ins like Visual Assist X, CodeRush or ReSharper — they are all supposed to support code re-factoring. You can locate these products in Wikipedia.

—SA


这篇关于在Visual Studio 2010中进行重构/封装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆