Detect long code lines in VS? - visual-studio-2010

I just ran across this terrible code:
string summary = Controls.BasePage1.GetLDA().ExecuteStringScalar(sb).Replace("'", "\\'");
It's not doing adequate null checks. Is there any way to detect long lines of code like this in a Visual Studio project?

Plain vanilla Visual Studio doesn't support search for long lines nor NullReferenceException checks.
There is an option to wrap long lines but it doesn't break lines to smaller units. (Tools -> Options... -> Text editor -> C# -> General -> Word wrap). If you widen your visual studio instance it will unwrap the line.
However, the functionality you are looking for is provided by third party plug-ins. I'm using ReSharper. It can find any possible NullReferenceExceptions in your code. Also it can automatically format your lines to whatever length you prefer. (Resharper -> Options -> Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping has quite a few options to fine tune code editing.)

Related

Customise "Light Bulb" Quick Action Rules

The question relates to where can one customise the rule set for the new Visual Studio 2015 Light Bulb or Quick Actions feature.
Specifically I want to disable the one imaged below, for "simplifying" String.IsNullOrWhiteSpace to string.IsNullOrWhiteSpace.
The warning message given is:
IDE0001 Name can be simplified.
Tools -> Options -> Text Editor -> C# -> Code Style
Then untick the following:
Prefer intrinsic predefined type keyword in member access expressions

Is there any way to turn off Resharper 7 auto formatting?

This has been driving me crazy, I've tried Resharper support with no solution, but wondered if anyone out there has experienced this.
When I update an existing method and hitting the curly brace or semi-colon, I am getting a double indent:
public void abc(int a, int b) {
var c; // <- after hitting return after the curly brace
var d;
var e;
}
Is there any way to completely turn off Resharper formatting? Or at least fix this problem? I've looked in the Resharper->Code Editing->C# but didn't find anything that worked.
PS - This is on VS 2010
Both ReSharper and Visual Studio have auto-formatting. But in C# they are usually triggered by pressing ; or }, not by carriage return, so either you describe your actions wrong or you've hit some kind of bug.
To turn off ReSharper auto-formatting, go to ReSharper | Options -> Environment | Editor and turn off "Auto-format on semicolon" and "Auto-format on closing brace". If that won't help against your bug you may want also to turn off "Auto-insert closing brace" on the same page.
To turn off Visual Studio auto-formatting, go to Tools | Options -> Text Editor | C# | Formatting | General and turn off "Automatically format ... " options.
But even without auto-format formatting would still be done on refactorings and quick fixes, so you may want to tune formatting options (besides or instead of turning off auto-format). First of all, go to Tools | Options -> Text Editor | C# | Tabs. Make sure that tab size and indent size are equal (ReSharper doesn't support different values here) and have correct value. Also choose between Insert spaces and Keep tabs. Then go to ReSharper | Options -> Code Editing | C# | Formatting style | Braces layout. Judging by your code, you prefer K&R style. So select "K&R style" value for the first 6 options on this page. These are most important settings, but you may also want to look at other formatting style settings to better adjust them for your style.

Single line formatting CSS with line break at certain length/column

Cutting to the chase:
Is there an option in VS or a plugin that can provide the ability to insert a line break after a certain amount of columns of a compressed/single line formatted Razor/HTML/ASPX page?
From:
To:
Tools -> Options -> Text Editor -> CSS -> Formatting
choose style: Compact rules
You can use resharper a visual studio plugin.
If you go to ReSharper -> Options -> Languages -> C# -> Formatting style -> Line Breaks and Wrapping
There is a host of options in there.
Tools -> Options -> Text Editor -> All Languages -> Word Wrap
or if you prefer:
Ctrl+E+W

Visual Studio: automatically open Intellisense

Is there a way to make Intellisense(CTRL+Space) automatically open after I type a letter? Its really annoying me to have to press CTRL+Space every line of code
What you describe is the default behavior. To restore it, use:
Tools -> Options -> Text Editor -> C# (e.g.)
Statement Completion -> Auto list members: Checked
Edit:
In C++ "Auto list members" does not apply to the first identifier in an expression, that is, when the identifier could be almost anything: a global variable, a keyword, a class member, etc. It does however apply (and does work) after the ".", "->", and "::" operators.
A workaround for a very common case of desiring auto listing for class members is to use the "this->" convention in your code, which some coding standards recommend anyway. The completion list will pop up immediately upon typing "->".
Default C++ IntelliSense does not open automatically when you are typing except for after ., -> and ::. The third party commercial extension Visual Assist X does provide that behavior though.

Code template's indentation is buggy for code behind files in VS2005?

Not sure if anyone else has come across this yet. I like to use a an indent of 2 or 3 and not the default 4 for visual studio because i find my code runs a bit far to the right and I prefer to not code over column 80 for readability's sake. When I change the indent and tabs to 2 using tools >> options >> Text Editor >> C# >> tabs and also set it to "keep tabs" then new classes created are fine. BUT if I create a new ASPX page with a code behind page, the code behind page's initial code keeps a 4 space indent although i specified 2. I have to format the document (a quick ctrl e, d) but it is still irritating. Anyone else come across this?
Try setting Tools -> Options -> Text Editor -> All Languages -> Tabs instead of C# -> Tabs.
Alternatively try a different font or try breaking your code up into smaller pieces by extracting methods via the Visual Studio built-in refactoring tools, etc.
Just had a look now. All languages are already set. I could break up my code further but don't want it to get into spaghetti code. I like my methods do a logical unit of work :)

Resources