NickStrupat.CrtpAnalyzer 1.0.0

Prefix Reserved
dotnet add package NickStrupat.CrtpAnalyzer --version 1.0.0
                    
NuGet\Install-Package NickStrupat.CrtpAnalyzer -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NickStrupat.CrtpAnalyzer" Version="1.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NickStrupat.CrtpAnalyzer" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NickStrupat.CrtpAnalyzer">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NickStrupat.CrtpAnalyzer --version 1.0.0
                    
#r "nuget: NickStrupat.CrtpAnalyzer, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NickStrupat.CrtpAnalyzer@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NickStrupat.CrtpAnalyzer&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NickStrupat.CrtpAnalyzer&version=1.0.0
                    
Install as a Cake Tool

CrtpAnalyzer

A standalone Roslyn analyzer (with code fix) that verifies the Curiously Recurring Template Pattern (CRTP) is used correctly.

A self-constrained generic type — interface ISelf<TSelf> where TSelf : ISelf<TSelf> or class Base<TSelf> where TSelf : Base<TSelf> — requires the implementing type itself to be passed as the self type argument. Supplying anything else still compiles, but breaks the pattern (its static abstract members and self-typed APIs become unusable).

public readonly struct MyDate : IParsable<DateOnly> // CRTP001: should be IParsable<MyDate>
{
}

Unlike CA2260 — which only knows a hardcoded list of BCL generic-math interfaces — this analyzer detects the CRTP shape structurally, so it also covers:

  • your own CRTP interfaces, and
  • the classic CRTP base-class pattern (class Entity<TSelf> where TSelf : Entity<TSelf>).

The included code fix rewrites the offending self type argument to the implementing type.

Diagnostic id CRTP001
Category Usage
Default severity Warning
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 142 6/26/2026