IvTem.TypeSafety 0.1.5

dotnet add package IvTem.TypeSafety --version 0.1.5
                    
NuGet\Install-Package IvTem.TypeSafety -Version 0.1.5
                    
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="IvTem.TypeSafety" Version="0.1.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IvTem.TypeSafety" Version="0.1.5" />
                    
Directory.Packages.props
<PackageReference Include="IvTem.TypeSafety" />
                    
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 IvTem.TypeSafety --version 0.1.5
                    
#r "nuget: IvTem.TypeSafety, 0.1.5"
                    
#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 IvTem.TypeSafety@0.1.5
                    
#: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=IvTem.TypeSafety&version=0.1.5
                    
Install as a Cake Addin
#tool nuget:?package=IvTem.TypeSafety&version=0.1.5
                    
Install as a Cake Tool

IvTem.TypeSafety

IvTem.TypeSafety is a Roslyn analyzer and source-generator package for expressing compile-time restrictions on generic type arguments that C# generic constraints cannot represent directly.

This project is AI-assisted. Planning and implementation are assisted by OpenAI Codex, with human review and ownership by Ivan Temelkov.

Status

The repository contains the 0.1.5 analyzer/source-generator package, package-content validation, NuGet/MSBuild transitive-enforcement integration tests, and a runnable sample.

Installation

Install the package in projects that declare or consume restricted generic APIs:

<PackageReference Include="IvTem.TypeSafety" Version="0.1.5" />

The package generates internal attributes into each consuming compilation:

  • IvTem.TypeSafety.DisallowTypesAttribute
  • IvTem.TypeSafety.DisallowExactTypesAttribute

No runtime assembly reference is required.

Quick Examples

Use DisallowTypes when derived, implemented, boxed, or otherwise definitely assignable type arguments should be rejected:

using IvTem.TypeSafety;

public sealed class Result<[DisallowTypes(typeof(System.Exception))] T>
{
}

Result<string> allowed = new();
// Result<System.InvalidOperationException> rejected = new(); // IVTS001

Use DisallowExactTypes when only the exact semantic type should be rejected:

using IvTem.TypeSafety;

public sealed class Payload<[DisallowExactTypes(typeof(string))] T>
{
}

Payload<object> allowed = new();
// Payload<string> rejected = new(); // IVTS001

Restrictions can be declared on generic types and generic methods, and supported contracts propagate through generic inheritance, interface implementation, method overrides, interface methods, and direct declaration signatures such as Wrapper<T> containing a Result<T> member.

See samples/IvTem.TypeSafety.Sample/ for a runnable project with valid usage and intentionally invalid examples kept out of compilation.

Diagnostics

All diagnostics are reported as errors:

ID Meaning
IVTS001 A constructed generic type or method uses a forbidden type argument.
IVTS002 A restriction attribute is configured with an invalid type list or unsupported forbidden type.
IVTS003 Generic signature propagation contains an unsupported cycle.
IVTS004 Reserved descriptor for contradictory restriction diagnostics; no current analyzer path emits it in 0.1.5.
IVTS005 A current-source lookalike attribute uses the IvTem.TypeSafety metadata name but not the expected v1 shape.

See docs/diagnostics.md for examples and remediation guidance.

Package Shape

IvTem.TypeSafety is packaged as a Roslyn analyzer/source-generator package. The .nupkg places IvTem.TypeSafety.dll under analyzers/dotnet/cs/netstandard2.0/ and intentionally does not include a runtime lib/ assembly.

The package also includes README.md, MIT license metadata, Git repository metadata, and a .snupkg symbol package. Version 0.1.1 aligned the analyzer DLL and PDB under the same package path so nuget.org can validate the symbols package. Version 0.1.2 lowers the Roslyn dependency baseline to support older .NET 8 development environments. Version 0.1.3 fixes false self-cycle diagnostics for generic types that mention their own constructed form in member signatures. Version 0.1.4 fixes source-backed diagnostic locations for IDE navigation. Version 0.1.5 limits diagnostics to project source files with rooted paths and excludes generated source paths.

The package includes a buildTransitive props asset so downstream projects can receive the analyzer when IvTem.TypeSafety flows as a normal transitive package dependency. See docs/limitations.md for the precise tested boundary.

Limitations

Version 0.1.5 intentionally uses definite-only analysis. It does not analyze reflection-created generic types, XML documentation cref values, type alias declarations, method-body contract propagation, transformed generic mappings such as Data<List<T>>, or generic constraint chains such as where T : U where U : Exception.

See docs/architecture.md for the implementation model and docs/limitations.md for deferred scenarios.

Development

Restore and build the repository with:

dotnet restore IvTem.TypeSafety.slnx
dotnet build IvTem.TypeSafety.slnx --no-restore
dotnet test IvTem.TypeSafety.slnx --no-build
dotnet pack -c Release
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
0.1.5 115 8/26/2026
0.1.4 108 8/26/2026
0.1.3 106 8/26/2026
0.1.2 100 8/26/2026
0.1.1 99 8/26/2026
0.1.0 105 8/26/2026