Boxing/unboxing should be avoided

Rule ND1314 Design

Boxing wraps a value type inside a System.Object on the managed heap (implicit); unboxing extracts it (explicit). More: https://msdn.microsoft.com/en-us/library/yz2be5wk.aspx

Disabled by default to avoid noise; re-activate if boxing/unboxing matters to your team.

How to fix

With .NET generics (especially generic collections), boxing/unboxing is rarely needed and can usually be refactored away. See: http://stackoverflow.com/questions/4403055/boxing-unboxing-and-generics

Profile for CPU-heavy methods using boxing/unboxing, especially in a loop, and refactor them. Severity is Low: more an advice than a problem.

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>Boxing/unboxing should be avoided</Name>
// <Id>ND1314:BoxingUnboxingShouldBeAvoided</Id>
warnif count > 0 from m in JustMyCode.Methods where 
  m.IsUsingBoxing || 
  m.IsUsingUnboxing
select new { 
   m, 
   m.NbLinesOfCode, 
   m.IsUsingBoxing, 
   m.IsUsingUnboxing,
   relyOn = 
      m.IsUsingBoxing && m.IsUsingUnboxing ? "boxing and unboxing" :
      m.IsUsingBoxing ? "boxing" : "unboxing",
  
   Debt = 5.ToMinutes().ToDebt(),
   Severity = Severity.Low
} 


//<Expl>
// The *{0}* relies on {4} that can negatively impact performances.
//</Expl>

//<Desc>
// *Boxing* wraps a value type inside a *System.Object* on the managed heap
// (implicit); *unboxing* extracts it (explicit). More:
// https://msdn.microsoft.com/en-us/library/yz2be5wk.aspx
//
// **Disabled by default** to avoid noise; re-activate if boxing/unboxing
// matters to your team.
//</Desc>

//<HowToFix>
// With .NET generics (especially generic collections), boxing/unboxing is
// rarely needed and can usually be refactored away. See:
// http://stackoverflow.com/questions/4403055/boxing-unboxing-and-generics
//
// Profile for CPU-heavy methods using boxing/unboxing, especially in a
// **loop**, and refactor them. Severity is **Low**: more an advice than a
// problem.
//</HowToFix>

Design: all 16 items