-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Performance.PreferLiteralOverInitOnlyFieldsRule(2.10)
Assembly: Gendarme.Rules.Performance
Version: 2.10
This rule looks for InitOnly fields (readonly in C#) that could be turned into Literal (const in C#) because their value is known at compile time. Literal fields don't need to be initialized (i.e. they don't force the compiler to add a static constructor to the type) resulting in less code and the value (not a reference to the field) will be directly used in the IL (which is OK if the field has internal visibility, but is often problematic if the field is visible outside the assembly).
Bad example:
public class ClassWithReadOnly {
static readonly int One = 1;
}
Good example:
public class ClassWithConst
{
const int One = 1;
}
- This rule is available since Gendarme 2.2
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!