Skip to content

Gendarme.Rules.BadPractice.AvoidVisibleConstantFieldRule(2.10)

Sebastien Pouliot edited this page Jan 22, 2011 · 2 revisions

AvoidVisibleConstantFieldRule

Assembly: Gendarme.Rules.BadPractice
Version: 2.10

Description

This rule looks for constant fields which are visible outside the current assembly. Such fields, if used outside the assemblies, will have their value (not the field reference) copied into the other assembly. Changing the field's value requires that all assemblies which use the field to be recompiled. Declaring the field as static readonly, on the other hand, allows the value to be changed without requiring that client assemblies be recompiled.

Examples

Bad example:

// if this fields is used inside another assembly then
// the integer 42, not the field, will be baked into it
public const int MagicNumber = 42;

Good example:

// if this field is used inside another assembly then
// that assembly will reference the field instead of
// embedding the value
static public readonly int MagicNumber = 42;

Notes

  • This rule is available since Gendarme 2.0
Clone this wiki locally