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
<PackageReference Include="NickStrupat.CrtpAnalyzer" Version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="NickStrupat.CrtpAnalyzer" Version="1.0.0" />
<PackageReference Include="NickStrupat.CrtpAnalyzer"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add NickStrupat.CrtpAnalyzer --version 1.0.0
#r "nuget: NickStrupat.CrtpAnalyzer, 1.0.0"
#:package NickStrupat.CrtpAnalyzer@1.0.0
#addin nuget:?package=NickStrupat.CrtpAnalyzer&version=1.0.0
#tool nuget:?package=NickStrupat.CrtpAnalyzer&version=1.0.0
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 |
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 |