TypeLogic.LiskovWingSubstitution 1.0.0

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

TypeLogic.LiskovWingSubstitution

NuGet Downloads .NET Standard Tests

A .NET library implementing the Liskov/Wing Substitution Principle for type variance checking (including generic typeParameters constraints validation).

This project emerged from previous R&D tests dealing with .NET generics: I needed an additional simple way to verify type variance against GenericTypeDefinition, complementing .NET's built-in type system capabilities.

What started as a proof-of-concept to simplify variance checking turned into a full-fledged library that extends .NET's type system that you may find educational or even practicalin some cases. The implementation is based from Barbara Liskov's and Jeannette Wing's work on behavioral subtyping, providing additional variance checking capabilities when working with GenericTypeDefinitions (especially in cases where non-generic Type inheritance is absent, as illustrated in the examples).

Features

  • Type variance checking according to Liskov/Wing Substitution Principle
  • Support for generic type parameter constraints
  • Caching of type variance relationships for performance
  • Instance-based variance checking
  • Support for generic type definitions
  • Full support for .NET Standard 2.0

Installation

The package can be installed via NuGet:

dotnet add package TypeLogic.LiskovWingSubstitution

Usage

Basic Type Variance Checking

using TypeLogic.LiskovWingSubstitution;

// Check if List<string> is variant of IEnumerable<object>
bool isVariant = typeof(List<string>).IsSubtypeOf(typeof(IEnumerable<object>));

// Check with runtime type information
bool isVariantWithType = typeof(List<string>).IsSubtypeOf(typeof(IEnumerable<object>), out Type runtimeType);

Instance-Based Variance Checking

using TypeLogic.LiskovWingSubstitution;

List<string> instance = new List<string>();

// Check with type parameter
bool isInstanceOfType = instance.IsInstanceOf(typeof(IEnumerable<object>), out var runtimeType);
// runtimeType should be IEnumerable<string>
using TypeLogic.LiskovWingSubstitution;

string instance = "this is a string";

// Check with against generic type with the corresponding runtimeType
bool isInstanceOfType = instance.IsInstanceOf(typeof(IEquatable<>), out var runtimeType);
// runtimeType should be IEquatable<string>

Generic Type Definition Support

using TypeLogic.LiskovWingSubstitution;

// Check if List<T> is variant of IEnumerable<>
bool isGenericVariant = typeof(List<int>).IsSubtypeOf(typeof(IEnumerable<>));

// Convert instance based on generic definition
string instance = "test";
var converted = instance.ConvertAs(typeof(IEnumerable<>)); // Converts to IEnumerable<char>

Features in Detail

Type Variance Checking

The library implements comprehensive type variance checking:

  • Direct type equality
  • Interface and inheritance hierarchy traversal
  • Generic type parameter constraints validation
  • Support for generic type definitions
  • Cached type relationship checks

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Where to get help

  • Open an issue in the repository with detailed steps to reproduce any bug or performance regression.
  • For performance changes, include benchmark output (use tools/compare-benchmarks.ps1 when relevant).

References

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • 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 154 12/26/2025
0.2.1 263 11/30/2025
0.2.0 264 11/30/2025
0.1.1 213 11/2/2025
0.1.0 208 11/2/2025