nuget.org : consttypeargs.core
Provides a simple framework for defining types that can be used to pass constant & static values as generic type arguments. These can be used in static contexts (such as static constructors & static methods), reduce the need to pass arguments through instance constructors, bypass restrictions on types of arguments that can be passed to a generic attribute, and more. Uses include scenarios such as array initialization, fixed-size buffers, compile-time configuration, type-safe enum-like values, compile-time validation, algorithm configuration, implementation of design patterns such as ECS, command, & strategy, and more. Creating new const type arguments is as simple as: public readonly struct Pos_32: IConstTypeArg<int> { public static int Value => 32; } public readonly struct Pos_1024: IConstTypeArg<int> { public static int Value => 1024; } Here's a very simple example of how this could be used: public class FixedSizeBuffer<TSize> where TSize : IConstTypeArg<int> { private byte[] buffer = new byte[TSize.Value]; // Buffer operations... } // Elsewhere in code: var largeBuffer = new FixedSizeBuffer<Pos_1024>(); var smallBuffer = new FixedSizeBuffer<Pos_32>();
Registry
-
Source
- JSON
purl: pkg:nuget/consttypeargs.core
Keywords:
constants
, const-type-args
, generics
, static-abstract-interface-members
, csharp
, dotnet
License: MIT
Latest release: 11 months ago
First release: about 1 year ago
Downloads: 636 total
Stars: 3 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 14 days ago