resharper

Invert “if” statement to reduce nesting

本小妞迷上赌 提交于 2019-11-28 06:55:51
问题 When I ran ReSharper on my code, for example: if (some condition) { Some code... } ReSharper gave me the above warning (Invert "if" statement to reduce nesting), and suggested the following correction: if (!some condition) return; Some code... I would like to understand why that's better. I always thought that using "return" in the middle of a method problematic, somewhat like "goto". 回答1: A return in the middle of the method is not necessarily bad. It might be better to return immediately if

How can I configure ReSharper's code cleanup on save?

耗尽温柔 提交于 2019-11-28 06:44:36
I would love to configure Visual Studio/ReSharper to run "Code cleanup" whenever I save a file. A bonus would be to configure this only for C# files, as I sometimes find that the cleanup on ASP.NET files does not work without introducing errors. Johnno Nolan You could record a macro( Ctrl + E , Ctrl + C ,Run, Ctrl + S ). Then run that instead of saving. Then all you need to do is assign CTRL + S to your macro. Public Module RecordingModule Sub CLEAN_AND_SAVE() DTE.ExecuteCommand ("ReSharper.ReSharper_CleanupCode") DTE.ActiveDocument.Save End Sub End Module This method will show the code clean

Resharper custom search pattern to warn IDisposable objects

倖福魔咒の 提交于 2019-11-28 06:16:12
问题 Since resharper still doesn't give out any warning regarding objects implementing IDisposable, I'd like to create some custom search patterns available in resharper 5.0. So far I have this: (And don't mind my replace comments in the patterns, I don't really care about it, I just want a clear warning in the code when dealing with disposable objects.) - <CustomPatterns> - <Pattern Severity="WARNING"> <Comment>This class implements IDisposable interface.</Comment> <ReplaceComment>Please use

Why can't I reference my class library?

二次信任 提交于 2019-11-28 06:07:31
I have a solution that contains a website and a class library in Visual Studio 2008. I then have another web site project outside of the solution that needs to reference the class library. I right click the Bin folder or Project and select Add Reference, then select my Class Library Project, it adds the 15 or so DLLs that the class library needs to the websites bin folder, but none of the .cs files recognize the using statements. using MyLibrary.MyFolder; It says that it can't resolve it, and ReSharper just says it can be safely removed since it's not being used. ReSharper can recognize that

'is' versus try cast with null check

风格不统一 提交于 2019-11-28 05:09:32
I noticed that Resharper suggests that I turn this: if (myObj.myProp is MyType) { ... } into this: var myObjRef = myObj.myProp as MyType; if (myObjRef != null) { ... } Why would it suggest this change? I'm used to Resharper suggesting optimization changes and code reduction changes, but this feels like it wants to take my single statement and turn it into a two-liner. According to MSDN : An is expression evaluates to true if both of the following conditions are met: expression is not null. expression can be cast to type . That is, a cast expression of the form (type)(expression) will complete

A tool like ReSharper, but for Java? [closed]

我们两清 提交于 2019-11-28 04:50:11
I have read a lot about ReSharper on here. It sounds like it has a lot of cool features to help the programmer out. Trouble is, I don't write C#. Is there any tool that has similar functionality to ReSharper, but for Java instead? Thank you! Use IntelliJ IDEA an IDE from JetBrains - the creator of ReSharper. It's not "like resharper" - it's the original and resharper is like it for C#. I believe most Java IDEs already have it - I certainly view ReSharper as the tool which brings Visual Studio up to the level of Eclipse :) Do you have any specific R# features in mind? Resharper was developed by

Impure method is called for readonly field

╄→гoц情女王★ 提交于 2019-11-28 04:15:43
I'm using Visual Studio 2010 + Resharper and it shows a warning on the following code: if (rect.Contains(point)) { ... } rect is a readonly Rectangle field, and Resharper shows me this warning: "Impure Method is called for readonly field of value type." What are impure methods and why is this warning being shown to me? First off, Jon, Michael and Jared's answers are essentially correct but I have a few more things I'd like to add to them. What is meant by an "impure" method? It is easier to characterize pure methods. A "pure" method has the following characteristics: Its output is entirely

Resharper- Find all unused classes

大憨熊 提交于 2019-11-28 04:01:45
I know how to find unused references of a single file by right clicking on the file and selecting the "Find Usages" option. Is there any way I can see or get the list of all the unused classes or files in my project ? First enable "Analyze Errors In Solution" (right-click on the Resharper icon in the status bar). Then right-click the solution node and select "Find Code issues". In the "Inspection results" tool window you can group by "Issue type" and look for "Type or type member is never used" to get all unused classes (and many more unused symbols). A second option (after enabling "Analyze

Disable, but not uninstall Resharper 4.x onwards

痴心易碎 提交于 2019-11-28 03:52:29
Any ideas on how to disable, but not uninstall Resharper 4.x or above? Rytmis You can disable ReSharper 4 and lower using the Visual Studio Add-In Manager (remove the check from check box on the left). In ReSharper 5 and above (tested up to version 7.0.1), this is how you can suspend ReSharper from the Tools > Options > Resharper Cherian The accepted answer does not work from resharper 5 onwards. You should suspend ReSharper from the Tools > Options > Resharper Oscar Mederos If you want to do it without clicking too much, open the Command Window ( Ctrl + W , A ) and type: ReSharper_Suspend or

Resharper Alt Enter not working

▼魔方 西西 提交于 2019-11-28 02:53:00
Help, I can't function without Resharper . All of a sudden my Alt + Enter ↵ shortcut (to bring up the action list) has stopped working. Anybody experienced this or know how to fix? Josh Close Symptom A: the menu pops up for a split second, then goes away. Fix using the following steps in numerical order. Symptom B: pressing Alt + Enter ↵ does nothing. Fix using Step #2 first then try Step #1 if the issue persists. Perform a Visual Studio reset: Run cmd.exe as Administrator cd C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ devenv.exe /ResetSettings Re-apply Visual Studio