ConstTypeArgs.Core
1.0.0
See the version list below for details.
dotnet add package ConstTypeArgs.Core --version 1.0.0
NuGet\Install-Package ConstTypeArgs.Core -Version 1.0.0
<PackageReference Include="ConstTypeArgs.Core" Version="1.0.0" />
<PackageVersion Include="ConstTypeArgs.Core" Version="1.0.0" />
<PackageReference Include="ConstTypeArgs.Core" />
paket add ConstTypeArgs.Core --version 1.0.0
#r "nuget: ConstTypeArgs.Core, 1.0.0"
#addin nuget:?package=ConstTypeArgs.Core&version=1.0.0
#tool nuget:?package=ConstTypeArgs.Core&version=1.0.0
ConstTypeArgs
The Const Type Args library provides a way to use type parameters to pass static & constant values to generic types & methods. These values, or const type arguments, are accessible at compile-time and can be used to define the behavior of a generic type or method, without the need to pass them as runtime arguments. This mimics template specialization in C++ and allows for a form of compile-time computation and value propagation. This is particularly useful in situations where compile-time safety and efficiency are important.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- No dependencies.
NuGet packages (22)
Showing the top 5 NuGet packages that depend on ConstTypeArgs.Core:
Package | Downloads |
---|---|
ConstTypeArgs.Ints
Builds on type of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass int values to generics at compile-time. This provides an analog to type specialization in C++, and can be used for scenarios such as: * Static configuration, * Eliminating unnecessary instance constructors, * "Passing" values to type initializers, * And more. Built-in const type arguments cover -1 to -15, 0 to 15, powers of 2 up to 65536, and more. Here's a simple demonstration showing how to define and use const type arguments and domain-specific type arguments: using ConstTypeArgs.Ints; // Const type arguments: public readonly struct _8 : K_Int<_8> { public static int Value => 8; } public readonly struct _32 : K_Int<_32> { public static int Value => 32; } public abstract class DefaultSize : Int<_32> { } // Usage: public class Foo<TSize> where TSize : K_Int { public static readonly int[] FooArray = new int[TSize.Value]; static Foo() { Console.WriteLine($"Array size is {FooArray.Length}"); } } // Elsewhere var foo = new Foo<_8>(); // Outputs "Array size is 8" foo = new Foo<DefaultSize>(); // Outputs "Array size is 32" |
|
ConstTypeArgs.Longs
Builds on type of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass long values to generics at compile-time. This provides an analog to type specialization in C++, and can be used for scenarios such as: * Static configuration, * Eliminating unnecessary instance constructors, * "Passing" values to type initializers, * And more. Built-in const type arguments cover -1 to -15, 0 to 15, powers of 2 up to 65536, and more. Here's a simple demonstration showing how to define and use const type arguments and domain-specific type arguments: using ConstTypeArgs.Longs; // Const type arguments: public readonly struct _8 : K_Long<_8> { public static long Value => 8; } public readonly struct _64_000 : K_Long<_64_000> { public static long Value => 64000; } public abstract class DefaultSize : Long<_64_000> { } // Usage: public class Foo<TSize> where TSize : K_Long { public static readonly long LargeArraySize = TSize.Value; // Code to initialize large arrays. static Foo() { Console.WriteLine($"Large array size is {LargeArraySize.Length}"); } } // Elsewhere var foo = new Foo<_8>(); // Outputs "Large array size is 8" foo = new Foo<DefaultSize>(); // Outputs "Large array size is 32" |
|
ConstTypeArgs.Ulongs
Builds on type of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass ulong values to generics at compile-time. This provides an analog to type specialization in C++, and can be used for scenarios such as: * Static configuration, * Eliminating unnecessary instance constructors, * "Passing" values to type initializers, * And more. Built-in const type arguments cover 0 to 15, powers of 2 up to 65536, and more. Here's a simple demonstration showing how to define and use const type arguments and domain-specific type arguments: using ConstTypeArgs.Ulongs; // Const type arguments: public readonly struct _8 : K_Ulong<_8> { public static ulong Value => 8; } public readonly struct _32 : K_Ulong<_32> { public static ulong Value => 32; } public abstract class DefaultSize : Ulong<_32> { } // Usage: public class Foo<TSize> where TSize : K_Ulong { public static readonly int[] FooArray = new int[TSize.Value]; static Foo() { Console.WriteLine($"Array size is {FooArray.Length}"); } } // Elsewhere var foo = new Foo<_8>(); // Outputs "Array size is 8" foo = new Foo<DefaultSize>(); // Outputs "Array size is 32" |
|
ConstTypeArgs.Nuints
Builds on types of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass nuint (UIntPtr) values to generics at compile-time. This provides an analog to type specialization in C++, and can be used for scenarios such as: * Static configuration, * Eliminating unnecessary instance constructors, * "Passing" values to type initializers, * And more. Here's a simple demonstration: using ConstTypeArgs.Nuints; public class Foo<TSize> where TSize : K_Nuint { public static readonly int[] FooArray = new int[TSize.Value]; static Foo() { Console.WriteLine($"Integer array size is {FooArray.Length}"); } } // Elsewhere var foo = new Foo<_3>(); // Outputs "Integer array size is 3" foo = new Foo<_16>(); // Outputs "Integer array size is 16" The following shows how a new nuint const type argument could be defined. public readonly struct _32 : K_Nuint<_32> { public static nuint Value => 32; } You can also create new domain-specific nuint const type arguments like so: public sealed class DefaultInitialCollectionSize : K_Nuint<_32>; |
|
ConstTypeArgs.Nints
Builds on types of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass nint (IntPtr) values to generics at compile-time. This provides an analog to type specialization in C++, and can be used for scenarios such as: * Static configuration, * Eliminating unnecessary instance constructors, * "Passing" values to type initializers, * And more. Here's a simple demonstration: using ConstTypeArgs.Nints; public class Foo<TSize> where TSize : K_Nint { public static readonly int[] FooArray = new int[TSize.Value]; static Foo() { Console.WriteLine($"Integer array size is {FooArray.Length}"); } } // Elsewhere var foo = new Foo<_3>(); // Outputs "Integer array size is 3" foo = new Foo<_16>(); // Outputs "Integer array size is 16" The following shows how a new nint const type argument could be defined. public readonly struct _32 : K_Nint<_32> { public static nint Value => 32; } You can also create new domain-specific nint const type arguments like so: public sealed class DefaultInitialCollectionSize : K_Nint<_32>; |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.2.0 | 175 | 8/27/2024 |
1.2.0-beta1 | 130 | 8/20/2024 |
1.0.0 | 320 | 7/1/2024 |
Initial release.