我应该使用VS 2008重构支持还是购买ReSharper?

时间:2009-02-17 22:50:32

标签: visual-studio-2008 refactoring resharper

我应该使用VS 2008重构支持还是购买ReSharper?

使用ReSharper可以使用VS 2008重构支持无法完成哪些非常好的事情?

7 个答案:

答案 0 :(得分:4)

为什么不download a 30 day free trial并找出你是否喜欢它?我很相信一旦你习惯了安装R#,你就不会想回去了。

只是文档右侧的绿色/橙色/红色错误栏就足够了,但重构速度要快得多,还有其他一些非常有用的功能,比如代码清理(CTRL + E + F),它们会重新格式化文档根据您的风格偏好。

答案 1 :(得分:2)

我喜欢Resharper的一个方面是你可以创建一个自定义的Type Members Layout并用它来格式化你的所有文件。

这意味着你可以在你喜欢的任何mannar中排序所有字段/属性/方法/构造函数/覆盖/接口实现/委托/枚举等等(包括按名称,访问修饰符等的子集),然后甚至包装如果你愿意,他们会在地区。

例如,以下是我目前编写的指南:

CONSIDER grouping members into the following sections in the specified order: 
•   All fields
•   All constructors
•   Public and protected properties
•   Public and protected methods
•   Events
•   All explicit interface implementations
•   Internal members
•   Private members
•   All nested types
When more than one access modifier is in a section, the most visible access modifier should come first (e.g. public before protected).
 DO use #region blocks around not publicly callable and explicit interface implementation groups. 
#region internal members
...
#endregion
#region private members
...
#endregion

这是我用来匹配它们的模板:

<?xml version="1.0" encoding="utf-8" ?>

<!--
I. Overall

I.1 Each pattern can have <Match>....</Match> element. For the given type declaration, the pattern with the match, evaluated to 'true' with the largest weight, will be used 
I.2 Each pattern consists of the sequence of <Entry>...</Entry> elements. Type member declarations are distributed between entries
I.3 If pattern has RemoveAllRegions="true" attribute, then all regions will be cleared prior to reordering. Otherwise, only auto-generated regions will be cleared
I.4 The contents of each entry is sorted by given keys (First key is primary,  next key is secondary, etc). Then the declarations are grouped and en-regioned by given property

II. Available match operands

Each operand may have Weight="..." attribute. This weight will be added to the match weight if the operand is evaluated to 'true'.
The default weight is 1

II.1 Boolean functions:
II.1.1 <And>....</And>
II.1.2 <Or>....</Or>
II.1.3 <Not>....</Not>

II.2 Operands
II.2.1 <Kind Is="..."/>. Kinds are: class, struct, interface, enum, delegate, type, constructor, destructor, property, indexer, method, operator, field, constant, event, member
II.2.2 <Name Is="..." [IgnoreCase="true/false"] />. The 'Is' attribute contains regular expression
II.2.3 <HasAttribute CLRName="..." [Inherit="true/false"] />. The 'CLRName' attribute contains regular expression
II.2.4 <Access Is="..."/>. The 'Is' values are: public, protected, internal, protected internal, private
II.2.5 <Static/>
II.2.6 <Abstract/>
II.2.7 <Virtual/>
II.2.8 <Override/>
II.2.9 <Sealed/>
II.2.10 <Readonly/>
II.2.11 <ImplementsInterface CLRName="..."/>. The 'CLRName' attribute contains regular expression
II.2.12 <HandlesEvent />
-->

<Patterns xmlns="urn:shemas-jetbrains-com:member-reordering-patterns">

  <!--Do not reorder COM interfaces-->
  <Pattern>
    <Match>
      <And Weight="100">
        <Kind Is="interface"/>
        <HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute"/>
      </And>
    </Match>
  </Pattern>

  <!--Special formatting of NUnit test fixture-->
  <Pattern RemoveAllRegions="true">
    <Match>
      <And Weight="100">
        <Kind Is="class"/>
        <HasAttribute CLRName="NUnit.Framework.TestFixtureAttribute" Inherit="true"/>
      </And>
    </Match>

    <!--Setup/Teardow-->
    <Entry>
      <Match>
        <And>
          <Kind Is="method"/>
          <Or>
            <HasAttribute CLRName="NUnit.Framework.SetUpAttribute" Inherit="true"/>
            <HasAttribute CLRName="NUnit.Framework.TearDownAttribute" Inherit="true"/>
            <HasAttribute CLRName="NUnit.Framework.FixtureSetUpAttribute" Inherit="true"/>
            <HasAttribute CLRName="NUnit.Framework.FixtureTearDownAttribute" Inherit="true"/>
          </Or>
        </And>
      </Match>
      <Group Region="Setup/Teardown"/>

    </Entry>

    <!--All other members-->
    <Entry/>

    <!--Test methods-->
    <Entry>
      <Match>
        <And Weight="100">
          <Kind Is="method"/>
          <HasAttribute CLRName="NUnit.Framework.TestAttribute" Inherit="false"/>
        </And>
      </Match>
      <Sort>
        <Name/>
      </Sort>
    </Entry>
  </Pattern>

  <!--Default pattern-->
  <Pattern RemoveAllRegions="true">
    <!--public delegate-->
    <Entry>
      <Match>
        <And Weight="100">
          <Access Is="public"/>
          <Kind Is="delegate"/>
        </And>
      </Match>
      <Sort>
        <Name/>
      </Sort>
      <Group/>
    </Entry>

    <!--public enum-->
    <Entry>
      <Match>
        <And Weight="100">
          <Access Is="public"/>
          <Kind Is="enum"/>
        </And>
      </Match>
      <Sort>
        <Name/>
      </Sort>
      <Group/>
    </Entry>

    <!--fields and constants-->
    <Entry>
      <Match>
        <Or>
          <Kind Is="constant"/>
          <Kind Is="field"/>
        </Or>
      </Match>
      <Sort>
        <Kind Order="constant field"/>
        <Static/>
        <Readonly/>
        <Access Order="public"/>
        <Name/>
      </Sort>
      <Group/>
    </Entry>

    <!--Constructors. Place static one first-->
    <Entry>
      <Match>
        <Kind Is="constructor"/>
      </Match>
      <Sort>
        <Static/>
      </Sort>
      <Group/>
    </Entry>

    <!--public and protected properties, indexers-->
    <Entry>
      <Match>
        <And>
            <Or>
              <Kind Is="property"/>
              <Kind Is="indexer"/>
            </Or>
            <Or>
            <Access Is="public"/>
            <Access Is="protected"/>
            </Or>
        </And>
      </Match>
      <Sort>
        <Access Order="public"/>
        <Name/>
      </Sort>
      <Group/>
    </Entry>

    <!-- Methods -->
    <Entry>
      <Match>
        <And>
            <Kind Is="method"/>
            <Or>
                <Access Is="public"/>
                <Access Is="protected"/>
            </Or>
        </And>
      </Match>
      <Sort>
        <Access Order="public"/>
        <Name/>
      </Sort>
      <Group/>
    </Entry>

    <!-- Events-->
    <Entry>
      <Match>
        <Kind Is="event"/>
      </Match>
      <Sort>
        <Name/>
      </Sort>
      <Group/>
    </Entry>

     <!--interface implementations-->
    <Entry>
      <Match>
        <And Weight="100">
          <Kind Is="member"/>
          <ImplementsInterface/>
        </And>
      </Match>
      <Sort>
        <ImplementsInterface Immediate="true"/>
        <Kind Order="property"/>
        <Name/>
      </Sort>
      <Group/>
    </Entry>

    <!--internal properties, indexers, methods-->
    <Entry>
      <Match>
        <And>
            <Or>
              <Kind Is="property"/>
              <Kind Is="indexer"/>
              <Kind Is="method"/>
            </Or>
            <Access Is="internal"/>
        </And>
      </Match>
      <Sort>
        <Access Order="public"/>
        <Kind Order="property"/>
        <Name/>
      </Sort>
      <Group Region="Internal Members"/>
    </Entry>

    <!--private properties, indexers, methods-->
    <Entry>
      <Match>
        <And>
            <Or>
              <Kind Is="property"/>
              <Kind Is="indexer"/>
              <Kind Is="method"/>
            </Or>
            <Access Is="private"/>
        </And>
      </Match>
      <Sort>
        <Access Order="public"/>
        <Kind Order="property"/>
        <Name/>
      </Sort>
      <Group Region="Private Members"/>
    </Entry>

    <!--all other members-->
    <Entry/>

    <!--nested types-->
    <Entry>
      <Match>
        <Kind Is="type"/>
      </Match>
      <Sort>
        <Name/>
      </Sort>
      <Group/>
    </Entry>
  </Pattern>
</Patterns>

这使您的代码格式化,以满足您公司的编码风格,就像单个键盘快捷键一样简单。

答案 2 :(得分:1)

使用Resharper。我用它多年了。一旦你学会了快捷方式,就像你聘请了另一个人为你工作:)

请注意,它可以设置为使用与IntelliJ Idea相同的键,因此如果您需要执行一些Java,您将已经知道如何使用(一个非常好的)Java IDE。

另外,请阅读此内容 - 31 days of resharper

答案 3 :(得分:0)

绝对至少尝试ReSharper。它比默认的VS2008重构更有效,并且可以很好地跟踪你的单元测试。

由于有免费试用,尝试它不应该受到伤害。

我已经使用它一段时间了,我不得不承认我再也不能回到普通的Visual Studio ...

答案 4 :(得分:0)

顺便说一句:还有Refactor! Pro。我在短时间内使用了试用版并喜欢它(还没有购买)。

与ReSharper一样,它提供了更多的重构,并且比Visual Studio重构工具更快。

答案 5 :(得分:0)

我喜欢Resharper的一件事是你可以使用Ctrl-Shift-Alt-Up或Down在文件中向上或向下移动方法/字段/属性等(直接在方法/字段/属性的上方或下方)它可以使用文件结构浏览器通过拖放查看和重新排列文件的结构。

答案 6 :(得分:0)

我尝试了30天试用,现在我迷上了R#