Skip to content

Gendarme.Rules.Concurrency.NonConstantStaticFieldsShouldNotBeVisibleRule(2.10)

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

NonConstantStaticFieldsShouldNotBeVisibleRule

Assembly: Gendarme.Rules.Concurrency
Version: 2.10

Description

This rule warns if a non-constant public static field is found. In a multi-threaded environment access to those fields must be synchronized.

Examples

Bad example:

class HasPublicStaticField {
    public static ComplexObject Field;
}

Good example:

class FieldIsReadonly {
    public readonly static ComplexObject Field = new ComplexObject();
}
class UseThreadStatic {
    [ThreadStatic]
    public static ComplexObject Field;
    public static InitializeThread ()
    {
        if (Field == null)
        Field = new ComplexObject ();
    }
}
Clone this wiki locally