./nugetz

#Char

35 packages tagged with “Char

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!

v1.0.0277
constantsconst-type-argsgenericsstatic-abstract-interface-memberschar