drl
drl

Reputation: 841

Custom naming rules in ReSharper

The project I'm working on (C# on VS 2015 with ReSharper 2016.1.2) has a new requirement which requires us to remove all usages of p_ prefixes in parameter names (p_Param becomes param).

I'd like to create a ReSharper Code Inspection Custom Pattern to take care of this for me (to match the string pattern with squiggly lines and auto-fix in the solution).

I've followed the tutorial at https://www.jetbrains.com/help/resharper/2016.1/Code_Inspection__Creating_Custom_Inspections_and_QuickFixes.html but I'm a bit stuck.

I've tried the following patterns:

I'd also need to transform the $varName$ identifier from PascalCase to cammelCase (no ideea how to do this).

When searching via 'Search now' - no results are found in either situation.

Any help is appreciated.

Upvotes: 2

Views: 970

Answers (1)

Brandon
Brandon

Reputation: 4613

Using ReSharper, you can change the naming style of variables and have it apply to an entire solution.

The location of this option will (probably) vary but for my version of R# (2016.1.2), it's under ReSharper->Options->Code Editing->C#->Naming Style:

enter image description here

From there, change the Entity Kinds to how you want them to appear. In mine, I prefer _lowerCamelCase for private instance fields for example.

Once your changes are made, find any field of that type in code (I'll use a private variable) that doesn't follow that format, click it and then click the light bulb to the left. From there mouse-over the arrow on "Rename to ......" and select Fix naming in solution.

enter image description here

You might have to do it a few times but that's how I rename stuff based on my preferred code style.

Upvotes: 1

Related Questions