nuget.org : 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"
Registry
-
Source
- JSON
purl: pkg:nuget/consttypeargs.longs
Keywords:
constants
, const-type-args
, generics
, static-abstract-interface-members
, long
, csharp
, dotnet
License: MIT
Latest release: about 1 year ago
First release: about 1 year ago
Downloads: 173 total
Stars: 2 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 15 days ago