NDepend.API Documentation
ILNestingDepth Property
NDepend.CodeModel Namespace > IMethod Interface : ILNestingDepth Property
Gets a numeric nullable value measuring this method body maximum nesting scopes depth.
Syntax
Nullable<ushort> ILNestingDepth {get;}

Property Value

null if this method is declared in a third-party assembly.
null if this method is abstract.
Otherwise returns this method body maximum nesting scopes depth.
Remarks
Methods IL Nesting Depth code metric description:
The metric Nesting Depth for a method is the maximum number of encapsulated scopes inside the body of the method. The metric IL Nesting Depth is computed from the IL code. Values computed are similar to what we would expect by computing them from the C# or VB.NET source code.
A testing condition with N conditions, such as if( i > 9 && i < 12), is considered as N scopes because it is possible to decompose such conditions into N atomic conditions.
When a method has a large number of case statements corresponding to a switch, the C# and VB.NET compiler generally produce optimizations while generating the IL. In such case, the IL Nesting Depth corresponding value might be slightly higher to what you would expect.

Recommendations:
Methods with a IL Nesting Depth value higher than 4 are hard to understand and maintain. Methods with a IL Nesting Depth value higher than 8 are extremely complex and should be split in smaller methods (except if they are automatically generated by a tool).

Requirements

Target Platforms: Windows 11, 10, 8, 7 and Linux, MacOS with net8.0, net7.0 or net6.0 installed

See Also

Reference

IMethod Interface
IMethod Members