Defining a custom naming rule

Oct 22, 2011 at 11:16 PM
Edited Oct 22, 2011 at 11:16 PM

Hi all.

I have property:  public string SelectedTargetOU {get; set; }

After enabling the SP0100 rules, I'm getting a violation "SP0100: Property name SelectedTargetOU doesn't conform the specified style: SampleName.".
The macro for the Property rule is: $(AaBb). 
How can I change the macro to accept the SelectedTargetOU property?

Oct 23, 2011 at 9:25 PM

Hi LevG,

You could try adding "OU" to the Abbreviations list.

Best regards,
Oleg Shuruev

Oct 23, 2011 at 11:11 PM

Thanks for the reply, Oleg.

But what if I need to use 3 sequential capital letters in, let's say, a property name? It will not be correct to fill the abbreviations list with all these combinations, the property above was just an example out of about 20 properties and fields where the rule fails.

In my opinion. there should be a macro which allows any combination of letters where the only condition is that the name of the property (a field, or a method) can be started by either a capital or a small letter.

Please let me know what you think.

Thanks, Lev.

Oct 24, 2011 at 3:20 PM

Hi LevG,

Please let me know if I didn't understand you right.

Here are the use-cases you might probably want to apply, besides using "Abbreviations".
(all examples are given for "Property" naming rule)

1. Hardcode all required exceptions.


2. Allow any name starting with capital letter.


What you've probably mentioned, is to create special macro, working the same as #2?
If so, is it really required?

Looking forward to your answer.

Best regards,
Oleg Shuruev

Oct 25, 2011 at 7:54 PM

Hi Oleg!

You understood me right! In my opinion there should be a special macro for the 2nd option.

I was using ReSharper for several months already before trying StyleCop, and I am pretty used to the "UpperCamelCase" macro. It supports both capital and small letters in any combination, as long as it starts with a capital letter.

It is not REALLY required StyleCop+ to have this macro, but in my opinion, it will be easier for people to define their requirements.

Thanks a lot for you help.


Oct 25, 2011 at 9:13 PM

Hi Lev,

It seems you're quite right and such macros could really be useful.
I've created an issue for myself and will probably implement it soon.

P.S. As for ReSharper, I am using it for several years and, as for v5, "UpperCamelCase" didn't allow "ClassABC" name, for example.
I will check it tomorrow on v6 just in case.

Best regards,
Oleg Shuruev