Configuring Hungarian Notation Rules

By default, StyleCop does not allow variable or field names to include Hungarian notation. This is enforced by rule SA1305, FieldNamesMustNotUseHungarianNotation.

The implementation of this rule is rather straightforward, assuming that any field or variable name which begins with one or two lower-case letters and is followed by an upper-case letter is guilty of using Hungarian notation. This is true in many cases such as sName, nAmount, ulCost, etc. However, this simple algorithm does not hold true for variables with names like isValid, doTask, onAction, etc. Each of these names begins with two lower-case letters followed by an upper-case letter, but none are using Hungarian notation.

StyleCop provides a mechanism for specifying one or two letter prefixes which are allowed to be used at the start of variable and field names. This list can be set for a project by bringing up the settings dialog for the project, and navigating to the Hungarian tab:

configuringhungariannotationrules_1.bmp

It may be desirable to provide this list within a parent settings file at the root of your development tree, so that these prefixes will be allowed on all projects within your environment. To learn how to share settings across multiple projects, click here.

Last edited Feb 14, 2011 at 5:03 PM by jasonall, version 5