Cenum 1.0.2
See the version list below for details.
dotnet add package Cenum --version 1.0.2
NuGet\Install-Package Cenum -Version 1.0.2
<PackageReference Include="Cenum" Version="1.0.2" />
paket add Cenum --version 1.0.2
#r "nuget: Cenum, 1.0.2"
// Install Cenum as a Cake Addin #addin nuget:?package=Cenum&version=1.0.2 // Install Cenum as a Cake Tool #tool nuget:?package=Cenum&version=1.0.2
Cenum
An implementation of a type safe & object oriented alternative to C# enum.
Background
Instead of being limited to a fixed set of integral values, imagine if enums were a fixed set of objects. They could have fields, properties and methods - just as other types do. The only difference would be that there would only ever be one instance for each value.
Usage
The source generator will scan the source code for classes
marked with [Enumeration]
attribute and then generate Enumerate()
method for them.
The method will enumerate all public static readonly
fields with the same type as the class itself.
Example
[Enumeration]
public partial class Number
{
public static readonly Number One = new(1);
public static readonly Number Two = new(2);
public static readonly Number Three = new(3);
private readonly int _value;
private Number(int value) => _value = value;
public override string ToString() => _value.ToString();
}
foreach (var number in Number.Enumerate())
{
Console.WriteLine(number.ToString());
}
// Output:
// 1
// 2
// 3
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.6.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.