Can StyleCop automatically fix anything?

No, frustratingly. That’s why Style Cop is counter-productive. Consistent formatting looks nice, but there’s little productivity benefit to it (what really makes code hard to read is length and indirection). Perfect spacing is not worth spending hours adjusting lines by hand. Of course, if there were an automated tool to achieve consistent formatting, I’d hook … Read more

Disable StyleCop for specific lines

You can suppress rules by adding attributes to blocks of code. Here’s a simple example on a class from the blog post linked below, but you can do it on various members individually: [SuppressMessage(“Microsoft.StyleCop.CSharp.DocumentationRules”, “SA1600:ElementsMustBeDocumented”)] public class MyUndocumentedClass { public void MyUndocumentedMethod {} } There’s a quick overview at an MSDN blog post and a … Read more

Code Cleanup – tool to move all using statements inside namespace in all cs files in my solution?

With Resharper it can be done in two steps. Set the checkbox “Add ‘using’ directive to the deepest scope” in Code Editing → C# → Code Style → Reference qualification. In the context menu of the solution choose “Cleanup Code…”. You might want to create a custom cleanup pofile that suits your needs before performing … Read more

C# – StyleCop – SA1121: UseBuiltInTypeAlias – Readability Rules

Just to clarify: not everyone agrees with the authors of StyleCop. Win32 and .NET guru Jeffrey Richter writes in his excellent book CLR via C#: The C# language specification states, “As a matter of style, use of the keyword is favored over use of the complete system type name.” I disagree with the language specification; … Read more

Should ‘using’ directives be inside or outside the namespace in C#?

There is actually a (subtle) difference between the two. Imagine you have the following code in File1.cs: // File1.cs using System; namespace Outer.Inner { class Foo { static void Bar() { double d = Math.PI; } } } Now imagine that someone adds another file (File2.cs) to the project that looks like this: // File2.cs … Read more

Transfer all ReSharper Settings between PCs

Since the export option within Resharper is only for code styles, you’ll need to be a bit craftier for all settings. From Peter Ritchie’s blog… …the settings are stored in “%userprofile%\application data\jetbrains\resharper\v4.0\vs9.0”. There are a couple of xml files in there that store your settings. Before you upgrade to the latest build, just copy those … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)