Builds on types of the ConstTypeArgs.Core library to provide const type arguments that allow you to use type parameters to pass double 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 Default, MinValue, MaxValue, E, Epsilon, Pi, Phi, Tau, NaN, PositiveInfinity, NegativeInfinity, and _0. Here's a simple demonstration showing how to define and use const type arguments and domain-specific type arguments: using ConstTypeArgs.Doubles; // Const type arguments: public readonly struct _1_2345 : K_Double<_1_2345> { public static double Value = 1.2345; } public readonly struct _6_789 : K_Double<_6_789> { public static double Value = 6.789; } public abstract class DefaultValue : Double<_1_2345> { } // Usage: public static class Foo<TDouble> where TDouble : K_Double { private static readonly double Value = TDouble.Value; } // Elsewhere: Console.WriteLine($"Foo's value if default: {Foo<DefaultValue>."); Console.WriteLine($"Foo's non-default value: {Foo<_6_789>.Value}.");
$ dotnet add package ConstTypeArgs.DoublesConst type arguments (also called const type args) are types used to pass constant & static values to generics through type parameters. These values are available at compile-time and can be used in static contexts, such as static constructors, static fields, and static methods. This can provide enhanced type safety, compile-time polymorphism, performance improvements, and more.
You can use types in the ConstTypeArgs.Doubles namespace for passing double values as const type arguments.
Usage scenarios include: