ConstTypeArgs.Core 1.0.0

There is a newer version of this package available.
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
                    
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="ConstTypeArgs.Core" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConstTypeArgs.Core" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ConstTypeArgs.Core" />
                    
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 ConstTypeArgs.Core --version 1.0.0
                    
#r "nuget: ConstTypeArgs.Core, 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 ConstTypeArgs.Core@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=ConstTypeArgs.Core&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ConstTypeArgs.Core&version=1.0.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.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.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.Floats

Builds on types of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass float 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 include Default, MinValue, MaxValue, E, Epsilon, Pi, Phi, Tau, NaN, PositiveInfinity, NegativeInfinity, and _0. Here's a simple demonstration showing how to define and use const type arguments and domain-specific type arguments: using ConstTypeArgs.Floats; // Const type arguments: public readonly struct _1_2345 : K_Float<_1_2345> { public static float Value = 1.2345; } public readonly struct _6_789 : K_Float<_6_789> { public static float Value = 6.789; } public abstract class DefaultValue : Float<_1_2345> { } // Usage: public static class Foo<TFloat> where TFloat : K_Float { private static readonly float Value = TFloat.Value; } // Elsewhere: Console.WriteLine($"Foo's value if default: {Foo<DefaultValue>."); Console.WriteLine($"Foo's non-default value: {Foo<_6_789>.Value}.");

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 198 8/27/2024
1.2.0-beta1 140 8/20/2024
1.0.0 346 7/1/2024

Initial release.