Ardalis.SmartEnum
9.0.0
dotnet add package Ardalis.SmartEnum --version 9.0.0
NuGet\Install-Package Ardalis.SmartEnum -Version 9.0.0
<PackageReference Include="Ardalis.SmartEnum" Version="9.0.0" />
<PackageVersion Include="Ardalis.SmartEnum" Version="9.0.0" />
<PackageReference Include="Ardalis.SmartEnum" />
paket add Ardalis.SmartEnum --version 9.0.0
#r "nuget: Ardalis.SmartEnum, 9.0.0"
#:package Ardalis.SmartEnum@9.0.0
#addin nuget:?package=Ardalis.SmartEnum&version=9.0.0
#tool nuget:?package=Ardalis.SmartEnum&version=9.0.0
Ardalis.SmartEnum
IMPORTANT This is the last MIT-licensed release of this library. Future releases will require a (potentially free) commercial license. Find out more
Classes to help produce strongly typed smarter enums in .NET.
A SmartEnum (smart enum) is an object-oriented alternative to C# enum types. Each value is an instance of a class, so it can carry its own data and behavior, while still offering enum-like lookup by name or value.
Release Notes
This is the last MIT-licensed release of this library (see above).
- Updated to latest supported .NET frameworks (.NET 10, .NET 11) with continued NetStandard2.0 support (#583)
- Breaking: dropped the
net6.0,net7.0, andnet8.0targets. Projects that can't use .NET 10+ get thenetstandard2.0build instead.
- Breaking: dropped the
- Breaking (Ardalis.SmartEnum.EFCore):
ConfigureSmartEnum()moved from theSmartEnum.EFCorenamespace toArdalis.SmartEnum.EFCore, matching the other packages. Changeusing SmartEnum.EFCore;tousing Ardalis.SmartEnum.EFCore;. - Each companion package now ships its own NuGet readme
- Updated dependencies to their latest secure versions (#583)
- Null checks now consistently use pattern matching (#550)
- Corrected the documented exception type for
FromValue(#549)
Usage
Define a smart enum by inheriting from SmartEnum<TEnum>:
using Ardalis.SmartEnum;
public sealed class TestEnum : SmartEnum<TestEnum>
{
public static readonly TestEnum One = new TestEnum(nameof(One), 1);
public static readonly TestEnum Two = new TestEnum(nameof(Two), 2);
public static readonly TestEnum Three = new TestEnum(nameof(Three), 3);
private TestEnum(string name, int value) : base(name, value)
{
}
}
Then look up and list values:
var two = TestEnum.FromName("Two"); // or TestEnum.FromValue(2)
if (TestEnum.TryFromValue(3, out var three))
{
Console.WriteLine(three.Name); // "Three"
}
foreach (var option in TestEnum.List)
{
Console.WriteLine($"{option.Name} = {option.Value}");
}
Smart enums can also carry behavior:
public abstract class EmployeeType : SmartEnum<EmployeeType>
{
public static readonly EmployeeType Manager = new ManagerType();
public static readonly EmployeeType Assistant = new AssistantType();
private EmployeeType(string name, int value) : base(name, value) { }
public abstract decimal BonusSize { get; }
private sealed class ManagerType : EmployeeType
{
public ManagerType() : base("Manager", 1) { }
public override decimal BonusSize => 10_000m;
}
private sealed class AssistantType : EmployeeType
{
public AssistantType() : base("Assistant", 2) { }
public override decimal BonusSize => 1_000m;
}
}
Companion packages add support for EF Core, Dapper, System.Text.Json, Json.NET, MessagePack, protobuf-net, Utf8Json, AutoFixture, ASP.NET Core model binding, and Ardalis.GuardClauses. See the full project README for details.
Roadmap
This is our roadmap for this package:
Version 9.x
This version. The last MIT-licensed package.
Version 15.x
The next version. It will have minimal changes from 9.x but will have a dual license and a compile-time license check and any planned breaking changes will be marked [Obsolete] if possible to signal what's coming. It will also be released both as Ardalis.SmartEnum and as NimbleTools.SmartEnum but with identical behavior to make upgrades as easy as possible, both now and in the future.
Why the jump from 9 to 15? We want to consolidate the 3 Ardalis packages that are moving to commercial licensing (GuardClauses, SmartEnum, Specification) and, like Aspire, we want to keep our version numbers separated from .NET's version numbers. Starting at 15 for all 3 lets us do that.
Version 16.x
This is where we expect to introduce potentially breaking changes as we rethink, refactor, and improve the implementation of the library. We will not break the API without a good reason, but there are some inconsistencies and places where we can improve the usability and sometimes the performance and this will be the time to make such changes.
Stay informed of changes by adding your email here: https://nimbletools.io/updates
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. net11.0 is compatible. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 5.0.0)
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
NuGet packages (133)
Showing the top 5 NuGet packages that depend on Ardalis.SmartEnum:
| Package | Downloads |
|---|---|
|
Ardalis.SmartEnum.SystemTextJson
System.Text.Json (de)serialization support for Ardalis.SmartEnum. |
|
|
Ardalis.SmartEnum.JsonNet
Json.NET (de)serialization support for Ardalis.SmartEnum. |
|
|
Ardalis.SmartEnum.EFCore
EFCore support for Ardalis.SmartEnum. |
|
|
Ardalis.SmartEnum.AutoFixture
AutoFixture support for Ardalis.SmartEnum. |
|
|
Miru
Package Description |
GitHub repositories (11)
Showing the top 11 popular GitHub repositories that depend on Ardalis.SmartEnum:
| Repository | Stars |
|---|---|
|
ardalis/CleanArchitecture
Clean Architecture Solution Template: A proven Clean Architecture Template for ASP.NET Core 10
|
|
|
amantinband/clean-architecture
The ultimate clean architecture template for .NET applications 💪
|
|
|
pdevito3/craftsman
A .NET scaffolding tool to help you stop worrying about boilerplate and focus on your business logic 🚀
|
|
|
CodeMazeBlog/CodeMazeGuides
Source code for 800+ C# and .NET articles from code-maze.com. Every article is a runnable solution, most with tests.
|
|
|
AntonioFalcaoJr/EventualShop
A state-of-the-art distributed system using Reactive DDD as uncertainty modeling, Event Storming as subdomain decomposition, Event Sourcing as an eventual persistence mechanism, CQRS, Async Projections, Microservices for individual deployable units, Event-driven Architecture for efficient integration, and Clean Architecture as domain-centric design
|
|
|
TuralSuleymani/the-real-DDD-CQRS-CleanArchitecture
A real-world example of a shopping basket API built with C#, showcasing Domain-Driven Design (DDD), Clean Architecture, and CQRS patterns. Includes features like basket management, discount application, and event-driven design with Kafka.
|
|
|
SteveDunn/Intellenum
Intelligent Enums
|
|
|
ChilliCream/hotchocolate-examples
|
|
|
pdevito3/QueryKit
🎛️ QueryKit is a .NET library that makes it easier to query your data by providing a fluent and intuitive syntax for filtering and sorting.
|
|
|
DevBetterCom/DevBetterWeb
A simple web application for devBetter
|
|
|
baotoq/micro-commerce
.NET 10 .NET Aspire
|
| Version | Downloads | Last Updated |
|---|---|---|
| 9.0.0 | 1,333 | 11/24/2026 |
| 8.2.0 | 9,925,594 | 11/19/2024 |
| 8.1.0 | 4,062,963 | 10/3/2024 |
| 8.0.0 | 5,379,027 | 1/16/2024 |
| 7.0.0 | 3,434,885 | 1/26/2023 |
| 2.1.0 | 5,230,837 | 4/5/2022 |
| 2.0.1 | 2,386,564 | 3/12/2021 |
| 2.0.0 | 649,100 | 10/1/2020 |
| 1.0.11 | 766,897 | 6/21/2020 |
| 1.0.10 | 5,633 | 6/19/2020 |
| 1.0.8 | 561,435 | 5/16/2019 |
| 1.0.7 | 4,821 | 3/29/2019 |
| 1.0.6 | 36,711 | 1/24/2019 |
| 1.0.5 | 26,438 | 8/22/2018 |
| 1.0.4 | 3,210 | 8/22/2018 |
| 1.0.3 | 37,978 | 2/19/2018 |
| 1.0.2 | 4,300 | 12/4/2017 |
| 1.0.1 | 3,456 | 12/1/2017 |
| 1.0.0 | 42,683 | 12/1/2017 |
* Last MIT-licensed release. See https://nimbletools.io/news/ardalis-nuget-packages/
* Breaking: now targets net10.0, net11.0, and netstandard2.0 (dropped net6.0, net7.0, net8.0) (#583)
* Breaking (Ardalis.SmartEnum.EFCore): ConfigureSmartEnum() moved from the SmartEnum.EFCore namespace to Ardalis.SmartEnum.EFCore
* Each companion package now ships its own NuGet readme
* Updated dependencies to latest secure versions (#583)
* Null checks now consistently use pattern matching (#550)
* Corrected the documented exception type for FromValue (#549)