-->

Resharper gotchas [closed]

2020-08-13 00:46发布

问题:

i absolutely adore ReSharper and would not work without it, but there are a few gotchas that i have run into and learned to avoid:

  • Allowing ReSharper to rename string literals automatically can really bite you in such instances as when your object variables match column names in your DAL SQL or other string constants. i have learned that instead of impatiently hitting the enter key when the second rename dialog appears i really need to see what ReSharper is suggesting and often skip the string literals rename step.
  • This one is a little more insidious: When you have Solution-Wide analysis turned on ReSharper will tell you whether or not public methods are used. This includes getters and setters in properties. It's a great feature but what ReSharper doesn't know is that when you're designing a view which will be displayed in the designer (form, user ctrl) that the property getters and setters are called at design time and don't show up in compilation. So ReSharper will suggest that those property's getters or setters can be made private or just removed. But if you make the adjustment and then load the view in the designer, the designer will crash because the property is not available and the error message is not exactly obvious. In a nutshell, a programmer needs to carefully consider property usage suggestions when designing a view.

Those are my biggies. What else is out there that could bite me and fellow ReSharper aficionados?

回答1:

When I run across preprocessor directives that use #ifs to do conditional compilation, and the current configuration is set so that a block of code is hidden, it doesn't seem to see the #if'd code and will recommend yanking out a variable that block of code uses, thinking it's never called.



回答2:

You can mark such properties by UsedImplicitly attribute and ReSharper will not suggest to remove it.



回答3:

We have used file-wide conditional compilation in the past, and Resharper goes completely nuts about those. It has no idea the conditions even exist, and loads of conflicts and errors can appear if both files declare the same constants and methods.

<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' Or '$(Configuration)|$(Platform)' == 'Release|x64'">
    <Compile Include="SomeFileFor.x64.cs">
        <SubType>Code</SubType>
    </Compile>
</ItemGroup>
<ItemGroup Condition=" !('$(Configuration)|$(Platform)' == 'Debug|x64' Or '$(Configuration)|$(Platform)' == 'Release|x64')">
    <Compile Include="SomeFileFor.x32.cs">
        <SubType>Code</SubType>
    </Compile>
</ItemGroup>


回答4:

Resharper is either ignoring completely or has quite different implementation of handling Warning As Errors project build switch. Additionally, last time when I checked, it ignored "Suppress warnings" block in project configuration when used in conjunction with Warnings as errors.



回答5:

The conditional compilation was added to ReSharper 8. Just get the last version.