Empty static constructor can be discarded
Warns about static constructors (cctor in IL, run by the CLR before the type's first use) containing no lines of code: useless, safely removable.
How to fix
Remove matched empty static constructors.
CQLinq source
This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.
// <Name>Empty static constructor can be discarded</Name>
// <Id>ND1308:EmptyStaticConstructorCanBeDiscarded</Id>
warnif count > 0 from m in JustMyCode.Methods where
m.IsClassConstructor &&
m.NbLinesOfCode == 0
select new {
m,
Debt = 2.ToMinutes().ToDebt(),
Severity = Severity.Medium
}
//<Expl>
// The *empty {0}* can be safely removed.
//</Expl>
//<Desc>
// Warns about *static constructors* (*cctor* in IL, run by the CLR before
// the type's first use) containing no lines of code: useless, safely
// removable.
//</Desc>
//<HowToFix>
// Remove matched empty *static constructors*.
//</HowToFix>
Open in the interactive Rules Explorer · All default rules
Design: all 16 items
- Avoid custom delegates ND1300
- Types with disposable instance fields must be disposable ND1301
- Disposable types with unmanaged resources should declare finalizer ND1302
- Methods that create disposable object(s) and that don't call Dispose() ND1303
- Disposable Types Must Unsubscribe Events ND1315
- Classes that are candidate to be turned into structures ND1304
- Avoid namespaces with few types ND1305
- Nested types should not be visible ND1306
- Declare types in namespaces ND1307
- Empty static constructor can be discarded ND1308
- Instances size shouldn't be too big ND1309
- Attribute classes should be sealed ND1310
- Don't use obsolete types, methods or fields ND1311
- Do implement methods that throw NotImplementedException ND1312
- Override equals and operator equals on value types ND1313
- Boxing/unboxing should be avoided ND1314