nuget.org : consttypeargs.chars
Builds on type of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass char 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 all ASCII & extended ASCII characters. Here's a simple demonstration showing how to define and use const type arguments and domain-specific type arguments: using ConstTypeArgs.Chars; // Const type arguments: public readonly struct Comma : K_Byte<Comma> { public static char Value => ','; } public readonly struct Semicolon : K_Byte<Semicolon> { public static char Value => ';'; } public readonly struct Slash : K_Byte<Slash> { public static char Value => (char)47; } public readonly struct VerticalBar : K_Byte<VerticalBar> { public static char Value => '|'; } public abstract class DefaultSeparator : Char<Semicolon> { } // Usage: public static class Foo<TChar> where TChar: K_Char { private static readonly char Separator = TChar.Value; public static void Output(string[] items) { foreach (var item in items) Console.Write($"{item}{Separator}"); } } // Elsewhere: var helloWorld = new string[] { "Hello", "World!" }; Foo<Comma>.Output(helloWorld); // Output: Hello,World! Foo<Slash>.Output(helloWorld); // Output: Hello/World! Foo<VerticalBar>.Output(helloWorld); // Output: Hello|World! Foo<DefaultSeparator>.Output(helloWorld); // Output: Hello;World!
Registry
-
Source
- JSON
purl: pkg:nuget/consttypeargs.chars
Keywords:
constants
, const-type-args
, generics
, static-abstract-interface-members
, char
, csharp
, dotnet
License: MIT
Latest release: about 1 year ago
First release: about 1 year ago
Downloads: 148 total
Stars: 3 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 15 days ago