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.
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.
// Install ConstTypeArgs.Core as a Cake Addin
#addin nuget:?package=ConstTypeArgs.Core&version=1.0.0

// Install ConstTypeArgs.Core as a Cake Tool
#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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (20)

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.Bytes

Builds on type of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass byte 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 values for 0 - 10, powers of 2, min & max values, and others. Here's a simple demonstration showing how to define and use const type arguments and domain-specific type arguments: using ConstTypeArgs.Bytes; // Const type arguments: public readonly struct _8 : K_Byte<_8> { public static byte Value => 8; } public readonly struct _32 : K_Byte<_32> { public static byte Value => 32; } public abstract class InitialValue : Byte<_32> { } // Usage: public class Foo<TSize> where TSize : K_Byte { 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<InitialValue>(); // Outputs "Array size is 32"

ConstTypeArgs.UInt128s

Builds on type of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass UInt128 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 values for 0 to 16 and others. Here's a simple demonstration showing how to define and use const type arguments and domain-specific type arguments: using ConstTypeArgs.UInt128s; // Const type arguments: public readonly struct _8 : K_UInt128<_8> { public static UInt128 Value => 8; } public readonly struct _64_000 : K_UInt128<_64_000> { public static UInt128 Value => 64000; } public abstract class DefaultSize : UInt128<_64_000> { } // Usage: public class Foo<TSize> where TSize : K_UInt128 { public static readonly UInt128 BigArraySize = TSize.Value; // Code to initialize very large arrays. static Foo() { Console.WriteLine($"Big array size is {BigArraySize.Length}"); } } // Elsewhere var foo = new Foo<_8>(); // Outputs "Big array size is 8" foo = new Foo<DefaultSize>(); // Outputs "Big 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>;

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 131 8/27/2024
1.2.0-beta1 115 8/20/2024
1.0.0 301 7/1/2024

Initial release.