ReSharper 4.5 complains about my private fields.

I just downloaded ReSharper 4.5.  I probably will blog more about my experience with it.

The first thing I noticed after upgrading to R# 4.5 is that I got a lot of complains (blue underlines) about my naming of non public fields. 


Like many developers I like to prefix my private variables with an underscore.  I know for the fact that I’m not alone that what Jeff Prosie says:

As a matter of personal preference, I typically prefix the names of private fields with an underscore (for example, _connection).  When I read the code back after a time away, this makes it obvious to me which fields are not intended for public consumption.  This conventions is used quite a lot in the .NET Framework – for example, in System.NET.HttpWebRequest and System.Web.HttpContext – but it is not used throughout.

Next thing I did is to check what controls this blue lines.  I went to ReSharper/Options/Naming Style.


To satisfy my naming style I click on Edit button to open an Edit “Instance fields (non public)” Rule Settings… window and typed an underscore (_) in Name Prefix text box:


After modifying “Instance fields (not public)” rule, ReSharper will not complain when we  add underscore to our private, internal, and protected fields.  But what if we want this rule for private fields only.  Well, in this case we need to define our own rule.  Naming Style window has two list boxes, the second one (User defined naming rules) allows us to define our own rule.


kick it on


Ask ReSharper to not to suggest to use var instead of a type name.

If you read my blog, you know I’m using ReSharper (R#).  Each time I install R#, I need to change the default settings.

By default R# will suggest  to use ‘var’ keyword when initializer explicitly declares type.


You can see the green wavy line bellow the type.  R# wants to replace the type with var keyword.  There’s nothing wrong to use new cool keyword but I personally prefer the type instead the var keyword.

R# by default also will hint to replace the type with var for implicit declaration.  If a suggestion is green wavy line, a hint is straight line that is two characters long.


So incase if you are also have a strong or may be mild desire to loose these suggestion and hint, follow this instruction:

  1. In Visual Studio select ReSharper/Optoins… or press Alt-R + O. It should open ReSharper – Options window.
  2. Click on Inspection Severity in Code Inspection section.
  3. On the right part of the dialog scroll down until you see Use ‘var’ keyword when initializer explicitly declares type.
  4. Click on arrow down button, and change from Show as suggestion to Do not show.
  5. On the next line bellow for Use ‘var’ keyword when possible change from Show as hint to Do not show.


kick it on


Disable automatic private modifier in ReSharper

If you use ReSharper, you notice that every time you create a global class variable without a modifier, ReSharper will add a private modifier for you.

You type:

string name;

ReSharper formats:

private string name;

Some people may be prefer this way.  I personally don’t see what values it adds.  My brain already knows that if there’s no modifier for a variable, than this variable is private.  I don’t need any extra information for my brain to process and filter.

Luckily for me ReSharper has an option to turn this feature off.

  1. Lunch ReSharper – Options dialog box.
  2. On the left part of the dialog select C#/Formatting Style/Other
  3. On the right part of the dialog uncheck ‘Use explicit private modifier’.


kick it on

.Net, Coding, ReSharper, Tips And Tricks, Visual Studio

Shortcut Key to Comment code in VS and SQL Server Management Studio

When we learn any programming language, one of the firsCtrl+Ct thing  we discover is the syntax how to comment our code.  Some of you probably already have been using this shortcut key for awhile.

Select multiple lines of code and press Ctrl+K,Ctrl+C, and you hard work is going to be ignored. To reverse just press Ctrl+K,Ctrl+U

These keystrokes will comment/uncomment your code only with line comment like // in C# or — in SQL.  I’m not aware how to comment code with block comment (/**/) without using a plug-in for VS.

One more thing.  If you need to comment/uncomment a single line, you don’t need to select the whole line.  Just move the cursor to any position on the line you want to comment, and let you fingers press the magic combination.

If you like me (there’s nothing wrong to be different from me) and use ReSharper, than you would like to use Ctrl+Alt+/ with line comment and Ctrl+Shift+/ with block comment.

kick it on

ReSharper, VS2005

Where’s my R# File Templates?

After installing ReSharper 4.0 Beta over a previous version, my user defined File Templates disappeared.  I was able to use my user defined Live Templates.  After some investigation, I was able to figure out how to get them back.

Actually they didn’t disappear, I just had to associate them with project types.


In case the same happens to you and you cannot find your File Templates here are the steps to get them back.

1. Follow the same steps as you would do when a adding a new item:

Click right button on your project in Visual Studio and select Add -> New from Template -> More… .

Now you should see ‘Choose Template’ dialog.


2. In ‘Choose Template’ dialog click on ‘Add to quicklist’ check box and select the type of the project your template should belong.  In my case I had to select ‘C# Projects’


I just want to mentioned that this behavior I’ve happened in VS2005, I haven’t check what happens in VS 2008.

.Net, MbUnit, ReSharper, Visual Studio, VS2005, VS2008

How To: Create a ReSharper File Template.

ReSharper is a wonderful tool that makes writing code much easier.  One of the features of this tool is ability to create templates.  With ReSharper you can create Live, Surround With, and File Template.  In this post I want to share with you how to create a File Template for MbUnit Test Fixture.

MbTest Template Selection After completion of this tutorial, you’ll be able to create an MbUnit Fixture by right clicking the test project and adding the test fixture.



Step 1: Open ReSharper – Options dialog.

Start Visual Studio and from menu bar select ReSharper – Options (you also can get there by pressing Alt-R + O).


Step 2: Create a new template.

  • In the left panel select File Templates under Templates section.
  • Then select User Templates in Available templates.
  • In this sample we’re going to create C# template, so select Class (C#) in Quick access list (it should be the first item in the list).
  • Last click on Create Template icon ReSharper Create Template icon to see Edit Template dialog box.

Step 3: Create and save MbUnit Test Fixture template.

  • In Name text box enter MbUnit Fixture.  It’s a name that will appear in the menu when you add a new test fixture.
  • In File name prefix text box enter MbTest.  It’s going to be a suggestion for your test file / class.

ReSharper Edit Template General 

ReSharper Template OptionsNext click on everywhere link next to the word Available to see the Template Options dialog box.  Select Only in projects for language radio button and chose C# projects including ASP.NET C#projects) from the drop-down control. Extension for created files leave as cs.

Now we are ready to create actual template.

Enter the code below into Template text.

   1: using MbUnit.Framework;
   3: namespace $NAMESPACE$
   4: {
   5:    [TestFixture]
   6:    [FixtureCategory("$CATEGORY$")]
   7:    [Author("Vadim Kreynin", "")]
   8:    public class $CLASS$ {$END$}
   9: }

I’m sure that you noticed $NAMESPACE$, $CATEGORY$, and $CLASS$.  These three are ReSharper variables.  You declare a variable by surrounding a word with $ sign.

The reason we created variables because we want to do something with them.

ReSharper has automatically created entries for our variables that looks like this:ReSharper Edit Template Variables

Click on Choose macro link and choose following options in Choose Macro dialog box.

Variable Available macro
$NAMESPACE$ Default namespace for current file
$CATEGORY$ Constant value
$CLASS$ Current file name without extension

Uncheck Editable Occurrence check box for NAMESPACE variable.

You can see that CATEGORY variable has a red link Constant value.  Click on it and enter Category in String value text box of Choose Parameter Value dialog box.

You’re done!  Click on OK button of Edit Template dialog box that should look like this: ReSharper Edit Template

Now you can start using this template.

Next time I’ll show how to create a Live Template for tests, test SetUp(s) and TearDown(s).


kick it on