resharper

Should I *always* favour implictly typed local variables in C# 3.0?

梦想的初衷 提交于 2019-11-27 03:04:16
问题 Resharper certainly thinks so, and out of the box it will nag you to convert Dooberry dooberry = new Dooberry(); to var dooberry = new Dooberry(); Is that really considered the best style? 回答1: It's of course a matter of style, but I agree with Dare: C# 3.0 Implicit Type Declarations: To var or not to var?. I think using var instead of an explicit type makes your code less readable.In the following code: var result = GetUserID(); What is result? An int, a string, a GUID? Yes, it matters, and

How to stop Resharper from line breaking after return keyword for long lines?

我的梦境 提交于 2019-11-27 02:31:06
问题 When I auto format with Resharper CTRL + ALT + SHIFT + F for lines longer than max line length (in my case say it's 80 characters), I get the following: return View(new ViewModel { Identifier = identifier, Files = service.AllFiles() }); But what I really want is it not to wrap after the "return" keyword (i.e. not have the return keyword on a line all on its own), like so: return View(new ViewModel { Identifier = identifier, Files = service.AllFiles() }); Does anyone know how to "configure"

Hitting Tab in Visual Studio selects block instead of adding indentation

只愿长相守 提交于 2019-11-27 02:06:59
问题 I am using Visual Studio 2015 and ReSharper 2016.2 and I have this strange behavior, that I probably activated (accidentally). When having the cursor in a line before the first word, hitting the Tab-key indents the line correctly: When the cursor is inside of any word inside the line, hitting the Tab-key selects the word or block. But the desired behavior would be to indent at the cursor (e.g. split a word into two words, if the cursor was inside of the word Stream after the letter r): Does

ReSharper formatting: align equal operands

狂风中的少年 提交于 2019-11-27 01:57:27
Note to Googlers , this question is somewhat out of date as the requested feature is now supported in the current version of ReSharper 2017.3.1 I like to formatting my code to align right side of equal operands. Like here: bool canRead = false; bool canReadClass = true; string className = boType.Name; I've switch to ReSharper recently and found it very useful but cannot find option allowing me format code in described way. Do you know if there is such option / plugin? Maybe you know other than ReSharp solution allowing that? EDIT: How to decide what part of code shall be aligned? My convention

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

旧街凉风 提交于 2019-11-27 01:27:55
问题 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. 回答1: 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

ReSharper complains when method can be static, but isn't

蹲街弑〆低调 提交于 2019-11-27 00:59:50
Why does ReSharper complain when a method can become static, but is not? Is it because only one instance of a static method is created (on the type) and thus save on performance? I find that comment very useful as it points out two important things: It makes me ask myself if the method in question should actually be part of the type or not. Since it doesn't use any instance data, you should at least consider if it could be moved to its own type. Is it an integral part of the type, or is it really a general purpose utility method? If it does make sense to keep the method on the specific type,

'is' versus try cast with null check

▼魔方 西西 提交于 2019-11-27 00:54:56
问题 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.

Impure method is called for readonly field

那年仲夏 提交于 2019-11-27 00:19:19
问题 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? 回答1: 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

Resharper Navigate to MVC View

不想你离开。 提交于 2019-11-26 22:41:50
问题 I recently upgraded to Resharper 8.1 and VS 2013 Before I could ctrl+click on a View to jump to it, but this no longer works. Is there a feature I need to enable to get it back? PartialView("_MainMenu", viewModel); 回答1: Go to Resharper->Manage Extensions and click the Online tab. Then search for Resharper.ExternalAnnotations, and install the package it comes up with. Finally go to Visual Studio Tools->Options and go to the Resharper->General options page. Click Suspend Now followed by Resume

ReSharper and var [duplicate]

此生再无相见时 提交于 2019-11-26 22:19:40
Possible Duplicate: Why does ReSharper want to use 'var' for everything? I have ReSharper 4.5 and have found it invaluable so far but I have a concern; It seems to want to make every variable declaration implicit (var). As a relatively new developer, how much should I trust ReSharper when it comes to this? Take the below code snippet from a method that Paints Tab Headers. TabPage currentTab = tabCaseNotes.TabPages[e.Index]; Rectangle itemRect = tabCaseNotes.GetTabRect(e.Index); SolidBrush fillBrush = new SolidBrush(Color.Linen); SolidBrush textBrush = new SolidBrush(Color.Black); StringFormat