Resharper: vars

It’s just an option. You can disable it: ReSharper -> Options -> Code Inspection -> Inspection Severity -> Code Redundencies -> Use ‘var’ keyword where possible: change this to “Do not show” There’s also the context (lightbulb) option which will take you in each direction – this is under ReSharper -> Options -> Languages -> … Read more

ReSharper conventions for names of event handlers

For C# (or VB), make the following change: ReSharper | Options | Languages | C# | C# Naming Style, Advanced settings… Change ‘Event subscriptions on fields’ from $object$_On$event$ to $object$_$event$. You may also want to add additional rules to entity kinds like ‘Types and namespaces’ to account for code-generated classes such as ‘Default’. For example, … Read more

When would SqlCommand.ExecuteReader() return null?

It’s a false positive. Reflecting on SqlDataReader.ExecuteReader, I can see that the only way the reader is returned as null is if the internal RunExecuteReader method is passed ‘false’ for returnStream, which it isn’t. In the depths of SqlDataReader, a reader constructor is always called at some point, so I’m pretty sure this is not … Read more

ReSharper – Possible Null Assignment when using Microsoft.Contracts

Note: as of the current R# 8.0 EAP, this functionality is included. Here’s the solution for the current (i.e. .NET 4.0) version of Code Contracts: Inside …\ExternalAnnotations\mscorlib\Contracts.xml, add the following: <assembly name=”mscorlib”> <member name=”M:System.Diagnostics.Contracts.Contract.Assert(System.Boolean)”> <attribute ctor=”M:JetBrains.Annotations.AssertionMethodAttribute.#ctor”/> <parameter name=”condition”> <attribute ctor=”M:JetBrains.Annotations.AssertionConditionAttribute.#ctor(JetBrains.Annotations.AssertionConditionType)”> <argument>0</argument> </attribute> </parameter> </member> <member name=”M:System.Diagnostics.Contracts.Contract.Assert(System.Boolean, System.String)”> <attribute ctor=”M:JetBrains.Annotations.AssertionMethodAttribute.#ctor”/> <parameter name=”condition”> <attribute ctor=”M:JetBrains.Annotations.AssertionConditionAttribute.#ctor(JetBrains.Annotations.AssertionConditionType)”> <argument>0</argument> </attribute> … Read more

Visual Studio or Resharper functionality for placement of using directives

UPDATE – ReSharper 2016.1: This option is now moved to Code Editing → C# → Code Style → Add ‘using’ directive to the deepest scope Have you tried the ReSharper option: Languages → C# → Formatting Style → Namespace Imports → Add using directive to the deepest scope I’m not sure whether R#’s code cleanup … Read more