Resharper Naming Style for Machine.Specifications

If you’re doing BDD-style specifications and using underscores within your variable names, the default Resharper settings will warn you about violating the naming style rules as shown below:

Fortunately, Machine.Specifications (MSpec) extends Resharper to allow for the creation of custom rules which affect only your MSpec types. To create a custom rule for MSpec, follow these steps:

Step 1: Open the Resharper Options Dialog.

Step 2: Navigate to Languages | Naming Style and under “User defined naming rules” click “Add”.

Step 3: This displays the “Edit Extended Naming Rule dialog.  In the “Rule Definition:” text box, give your new rule a name such as “Machine.Specifications Rules”.

Step 4: Within the Affected entities list, un-check Class and scroll to the bottom to locate the entries starting with Machine.Specifications. Select all of these entries.

Step 5: Select all options under Access rights: and leave options under Static/non-static: selected.

Step 6: Add a new naming style to associate this rule to by clicking the Add icon and selecting the desired naming style (e.g. all_lower).

The following diagram shows the dialog after these steps:

After selecting OK, Resharper now ignores the naming warnings for the MSpec types:

About Derek Greer

Derek Greer is a consultant, aspiring software craftsman and agile enthusiast currently specializing in C# development on the .Net platform.
This entry was posted in Uncategorized and tagged , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Pawel

    Thanks, it really helped. :) I just had to add warning 169 to suppressed list in project’s properties so it does not complain about delegates not being used (context, of).

  • Pingback: NullReference » Blog Archive » More MSpec – ReSharper love

  • http://lunaverse.wordpress.com Tim Scott

    I was elated to find your post.

    But it’s not working for me. I have triple verified that I did it exactly as you show. I suspended/re-enabled ReSharper and even closed and reopened the solution. The custom rule is having no effect. The only difference I can see is that I’m using RS 5.1. Any ideas?

  • http://lunaverse.wordpress.com Tim Scott

    I figured out the problem. Under Naming Style for C#, I had “Override common settings” checked. I solved it by creating the customer rule under C# instead of common.

    • Derek

      I apologize for just approving these today. For some reason your comments got flagged as spam.

  • http://blog.vizioz.com Chris Houston

    Hi Derek,

    This is just what I was looking for :)

    I also had the same issue as Tim and had to add the rule into the C# section as well. I think this might be something to do with having StyleCop for Resharper installed but I’m not 100% sure.

    Chris

    • DavidS

      No it’s nothing to do with the StyleCop for Resharper as I don’t have it on my computer. :)

  • Josh

    What’s the VS style you are using called? Thanks.