Arcturus.SmartEnums 2026.8.27.364

dotnet add package Arcturus.SmartEnums --version 2026.8.27.364
                    
NuGet\Install-Package Arcturus.SmartEnums -Version 2026.8.27.364
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Arcturus.SmartEnums" Version="2026.8.27.364" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Arcturus.SmartEnums" Version="2026.8.27.364" />
                    
Directory.Packages.props
<PackageReference Include="Arcturus.SmartEnums" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Arcturus.SmartEnums --version 2026.8.27.364
                    
#r "nuget: Arcturus.SmartEnums, 2026.8.27.364"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Arcturus.SmartEnums@2026.8.27.364
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Arcturus.SmartEnums&version=2026.8.27.364
                    
Install as a Cake Addin
#tool nuget:?package=Arcturus.SmartEnums&version=2026.8.27.364
                    
Install as a Cake Tool

Arcturus SmartEnums

Type-safe string-backed enumerations for .NET with built-in JSON serialization support.

Features

  • Type-Safe: Strongly-typed wrapper around string values with compile-time safety
  • JSON Serialization: Automatic System.Text.Json support - serializes as plain strings
  • Value Parsing: Built-in FromValue and TryFromValue factory methods
  • Two Usage Patterns: Manual inheritance or source-generated with attributes
  • Immutable: Record-based design with value equality semantics
  • Validation: Automatic validation of non-empty string values

Installation

dotnet add package Arcturus.SmartEnums

Usage

Use the [SmartEnum] attribute to automatically generate a complete smart enum implementation:

using Arcturus.SmartEnums;

[SmartEnum(
    "Pending=pending",
    "InProgress=in_progress",
    "Completed=completed",
    "Cancelled=cancelled")]
public partial record OrderStatus;

// Usage
var status = OrderStatus.Pending;
var parsed = OrderStatus.FromValue("in_progress");
var json = JsonSerializer.Serialize(status); // "pending"

Option 2: Manual Inheritance

For more control, inherit from SmartEnum<T> and implement ISmartEnum<T>:

using Arcturus.SmartEnums;

[JsonConverter(typeof(SmartEnumJsonConverter<Status>))]
public sealed record Status : SmartEnum<Status>, ISmartEnum<Status>
{
    public static readonly Status Pending = new("pending");
    public static readonly Status Active = new("active");
    public static readonly Status Disabled = new("disabled");

    private Status(string value) : base(value) { }

    public static Status FromValue(string value)
    {
        return value switch
        {
            "pending" => Pending,
            "active" => Active,
            "disabled" => Disabled,
            _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown Status value.")
        };
    }

    public static bool TryFromValue(string value, out Status? result)
    {
        switch (value)
        {
            case "pending": result = Pending; return true;
            case "active": result = Active; return true;
            case "disabled": result = Disabled; return true;
            default: result = null; return false;
        }
    }
}

API Reference

SmartEnum<T>

Base class for smart enum implementations.

public abstract record SmartEnum<T> where T : SmartEnum<T>
{
    public string Value { get; }
    protected SmartEnum(string value);
    public override string ToString();
}

ISmartEnum<T>

Interface defining factory methods for parsing string values.

public interface ISmartEnum<T> where T : ISmartEnum<T>
{
    string Value { get; }
    static abstract T FromValue(string value);
    static abstract bool TryFromValue(string value, out T? result);
}

[SmartEnum] Attribute

Marks a partial record/class for code generation.

[SmartEnum("Name", "OtherName=other_value")]
public partial record MyEnum;

Syntax:

  • "Name" - Member name and serialized value are both "Name"
  • "Name=value" - Member name is "Name", serialized value is "value"

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.8.27.364 108 8/27/2026