NDepend.API Documentation
NbLinesOfCode Property (ICodeContainer)
NDepend.CodeModel Namespace > ICodeContainer Interface : NbLinesOfCode Property
Gets a numeric nullable value counting the number of logical lines of code for this code element.
Syntax
Nullable<uint> NbLinesOfCode {get;}

Property Value

null if this code element is defined in a third-party assembly.
null if the PDB file of this assembly or code element parent's assembly, hasen't been found.
null if this code element is an interface, an enumeration, an abstract method or a default constructor.
Otherwise returns the number of logical lines of code for this code element.
Remarks
This metric (known as LoC) can be computed only if PDB files are present.
NDepend computes this metric directly from the information provided in PDB files.
The LoC for a method is equal to the number of sequence points found for this method in the PDB file.
A sequence point is used to mark a spot in the IL code that corresponds to a specific location in the original source.
More info about sequence points can be found here
Notice that sequence points which correspond to C# braces‘{‘ and ‘}’ are not taken account.
Computing the number of lines of code from PDB’s sequence points allows to obtain a logical LoC of code instead of a physical LoC (i.e directly computed from source files).
Two significant advantages of logical LoC over physical LoC are: Notice that the LoC for a type is the sum of its methods’ LoC, the LoC for a namespace is the sum of its types’ LoC, the LoC for an assembly is the sum of its namespaces’ LoC and the LoC for a code base is the sum of its application assemblies LoC.
Here are some observations: Recommendations:
Methods where NbLinesOfCode is higher than 20 are hard to understand and maintain.
Methods where NbLinesOfCode is higher than 40 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

ICodeContainer Interface
ICodeContainer Members