PostSharp 6.7 / / Post­Sharp Documentation / Deployment and Configuration / Licensing / License Types / Per-Usage Licenses / Number of Enhanced Lines of Code

Number of Enhanced Lines of Code

PostSharp uses a custom algorithm to count the number of lines in a given type for the purposes of per-usage licensing and to check for PostSharp Community limits. This algorithm has been selected for its high performance, high relevance, and low sensitivity to coding style. We do not pretend this is the best way to count lines of code (we believe there isn't one), but it's a reasonable choice for this purpose.


It's important to understand that the unit of counting is the enhanced type (class or struct). If you enhance a single method or other member of a type, PostSharp will consider that the whole type has been enhanced. This approach is a compromise of relevance and performance.

PostSharp uses the following rules to measure the number of lines of code in each type:

  • one line for each declaration (i.e. for each class, struct, delegate, enum, property, property accessor, event, event accessor, method, field);

  • one line for each debugger sequence point (i.e. each unique source code location where a breakpoint can be enabled), as emitted by the C# compiler, minus two for the opening and closing bracket, typically;

Therefore, we do not count lines of code for namespaces, generic parameters, or custom attributes.

Estimating the number of lines of code in a repo

To estimate how many lines of code are there in your project as seen by our algorithm, you can run the tool found at (make sure to download the latest release) in your repository after building your binaries. The tool uses the same algorithm as the licensing code inside PostSharp.

The tool tells you the total number of lines of your project. Telemetry data shows that customers typically apply aspects to 10-20% of their code. This should give you an idea of how many lines of code you will need to purchase. You can always start small and increase later, of course.

Effect of compiler settings

When the code is built with optimizations (this usually happens in Release builds), the resulting IL code may be shorter. In such a case, the number of lines of code that PostSharp detects may differ from results based a non-optimized (Debug) build. Because of the algorithm keeping the highest number for each type during aggregation, we will probably take the Debug build into account.

Note that different versions of the C# compiler may emit a slightly different number of sequence points and affect our algorithm in a way that we cannot control.