Don't tag instance fields with ThreadStaticAttribute

Rule ND2504 .NET Framework Usage / System.Threading

Warns when System.ThreadStaticAttribute tags instance fields: per documentation it is exclusively for static fields. https://msdn.microsoft.com/en-us/library/system.threadstaticattribute

How to fix

Ensure all fields tagged ThreadStaticAttribute are static.

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>Don't tag instance fields with ThreadStaticAttribute</Name>
// <Id>ND2504:DontTagInstanceFieldsWithThreadStaticAttribute</Id>

warnif count > 0
from f in Application.Fields 
where !f.IsStatic && 
       f.HasAttribute ("System.ThreadStaticAttribute".AllowNoMatch())
select new {
   f,
   Debt = 10.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *instance {0}* shouldn't be tagged with *ThreadStaticAttribute*.
// This attribute is intended to be used exclusively
// with fields that are declared as *static*.
//</Expl>

//<Desc>
// Warns when **System.ThreadStaticAttribute** tags *instance* fields: per
// documentation it is exclusively for *static* fields.
// https://msdn.microsoft.com/en-us/library/system.threadstaticattribute
//</Desc>

//<HowToFix>
// Ensure all fields tagged *ThreadStaticAttribute* are *static*.
//</HowToFix>

.NET Framework Usage / System.Threading: all 6 items