TSelfGeneric 1.0.0

dotnet add package TSelfGeneric --version 1.0.0
                    
NuGet\Install-Package TSelfGeneric -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="TSelfGeneric" 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="TSelfGeneric" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="TSelfGeneric">
  <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 TSelfGeneric --version 1.0.0
                    
#r "nuget: TSelfGeneric, 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 TSelfGeneric@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=TSelfGeneric&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=TSelfGeneric&version=1.0.0
                    
Install as a Cake Tool

TSelfGeneric Analyzer

When naming an generic attribute TSelf (Case Insensitivity) the anazlyser will check if the inheriting class or implenting interface is implenting it or is a TSelf generic argument. Only C# is now supported.

interface ISelfRequested<TSelf> where TSelf : ISelfRequested<TSelf> { }
//                                 it's a good idea to restrict the TSelf in a cricular way.

class Implementation : ISelfRequested<Implementation> { }

class BadImplementation : ISelfRequested<Implementation> { }
//                                       ~~~~~~~~~~~~~~
//                      Warning here, should be BadImplementation class.

// No error because the generic parameter is fill with an other generic paramter with the same objectif
// This give the task of filling the paramter to an upper level of inheritance.
abstract class NotImplementation<TSelf> : ISelfRequested<TSelf> where TSelf : NotImplementation<TSelf> { }
// abstract is not needed, i see some case where you can strange code that can use it. BUT... meh

If you do not like duck typing you can use an attriubte on the generic param.

// You need to define it yourself outisde an namsapce
[AttributeUsage(AttributeTargets.GenericParameter)]
public class TSelfAttribute : Attribute { }

interface ISelfRequested<[TSelf] T> where T : ISelfRequested<T> { }

class Implementation : ISelfRequested<Implementation> { }

class BadImplementation : ISelfRequested<Implementation> { }
//                                       ~~~~~~~~~~~~~~
//                      Warning here, should be BadImplementation class.

Not inheriting the aspect of the TSelf when passing a generic argument will result in a warning.

interface ISelfRequested<TSelf> where TSelf : ISelfRequested<TSelf> { }

class SomeImplementation<T> : ISelfRequested<T> where T : ISelfRequested<T> { }
//                       ~
//  Warning here, should be name TSelf or as the TSelfAttribute like [TSelf] T.

TODO:

  • Fix string localisation bug (Using US and not FR when set to FR)
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 138 8/14/2025