Enums.NET alternatives and similar packages
Based on the "Misc" category.
Alternatively, view Enums.NET alternatives based on common mentions on social networks and blogs.
-
Polly
Express transient exception handling policies such as Retry, Retry Forever, Wait andRetry or Circuit Breaker in a fluent manner. (.NET 3.5 / 4.0 / 4.5 / PCL / Xamarin) -
FluentValidation
A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules. -
Humanizer
Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities -
ReactJS.NET
ReactJS.NET is a library that makes it easier to use Babel along with Facebook's React and JSX from C#. -
Jint
Javascript interpreter for .NET which provides full ECMA 5.1 compliance and can run on any .NET plaftform. -
YoutubeExplode
Ultimate library for extracting metadata and downloading Youtube videos and playlists. -
Coravel
Near-zero config .NET Core library that makes Task Scheduling, Caching, Queuing, Mailing, Event Broadcasting (and more) a breeze! -
Jurassic
A implementation of the ECMAScript language and runtime. It aims to provide the best performing and most standards-compliant implementation of JavaScript for .NET. -
HidLibrary
This library enables you to enumerate and communicate with Hid compatible USB devices in .NET. -
Warden
Define "health checks" for your applications, resources and infrastructure. Keep your Warden on the watch -
Jot
a library for persisting and restoring application state (a better alternative to .settings files). -
ByteSize
ByteSize is a utility class that makes byte size representation in code easier by removing ambiguity of the value being represented. ByteSize is to bytes what System.TimeSpan is to time. -
Mediator.Net
A simple mediator for .Net for sending command, publishing event and request response with pipelines supported -
SolidSoils4Arduino
C# .NET - Arduino library supporting simultaneous serial ASCII, Firmata and I2C communication -
FormHelper
Form & Validation Helper for ASP.NET Core. Form Helper helps you to create ajax forms and validations without writing any javascript code. (Compatible with Fluent Validation) -
DeviceDetector.NET
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model. -
Jering.Javascript.NodeJS
Invoke Javascript in NodeJS, from C# -
https://github.com/minhhungit/ConsoleTableExt
Fluent library to create table for .Net console application. -
Outcome.NET
Never write a result wrapper again! Outcome.NET is a simple, powerful helper for methods that return a value, but sometimes also need to return validation messages, warnings, or a success bit. -
FlatMapper
A library to import and export data from and to plain text files in a Linq compatible way. -
NaturalSort.Extension
Extension method for StringComparer that adds support for natural sorting (e.g. "abc1", "abc2", "abc10" instead of "abc1", "abc10", "abc2"). -
trybot
A transient fault handling framework including such resiliency solutions as Retry, Timeout, Fallback, Rate Limit and Circuit Breaker. -
AdaskoTheBeAsT.FluentValidation.MediatR
FluentValidation behavior for MediatR -
Validot
Validot is a performance-first, compact library for advanced model validation. Using a simple declarative fluent interface, it efficiently handles classes, structs, nested members, collections, nullables, plus any relation or combination of them. It also supports translations, custom logic extensions with tests, and DI containers. -
.NET Fiddle
Write, compile and run C# code in the browser. The C# equivalent of JSFiddle. -
MSBuild ILMerge task
MSBuild ILMerge task is a NuGet package allows you to use the famous ILMerge utility in automated builds and/or Visual Studio projects.
Get performance insights in less than 4 minutes
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest. Visit our partner's website for more details.
Do you think we are missing an alternative of Enums.NET or a related project?
README
v3.0 Changes
One of the major changes for v3.0 is the deprecation of the NonGenericEnums
, NonGenericFlagEnums
, UnsafeEnums
, and UnsafeFlagEnums
classes whose methods have been added to the Enums
and FlagEnums
classes to better match System.Enum
and provide better discoverability. To help you migrate your code to using the new methods I have created the C# roslyn analyzer Enums.NET.Analyzer
which provides a code fix to migrate your usages of the non-generic and unsafe methods to the new methods.
Enums.NET
Enums.NET is a high-performance type-safe .NET enum utility library which provides many operations as convenient extension methods. It is compatible with .NET Framework 4.5+ and .NET Standard 1.0+.
I'm trying to integrate some of Enums.NET's improvements into corefx so if interested in its progress please check out the proposal here.
What's wrong with System.Enum
- Nearly all of
Enum
's static methods are non-generic leading to the following issues.- Requires the enum type to be explicitly specified as an argument and requires invocation using static method syntax such as
Enum.IsDefined(typeof(ConsoleColor), value)
instead of what should bevalue.IsDefined()
. - Requires casting/unboxing for methods with an enum return value, eg.
ToObject
,Parse
, andGetValues
. - Requires boxing for methods with enum input parameters losing type-safety, eg.
IsDefined
andGetName
.
- Requires the enum type to be explicitly specified as an argument and requires invocation using static method syntax such as
- Support for flag enums is limited to just the
HasFlag
method which isn't type-safe, is inefficient, and is ambiguous as to whether it determines if the value has all or any of the specified flags. It's all by the way. - Most of its methods use reflection on each call without any sort of caching causing poor performance.
- The pattern to associate extra data with an enum member using
Attribute
s is not supported and instead requires users to manually retrieve theAttribute
s via reflection. This pattern is commonly used on enum members with theDescriptionAttribute
,EnumMemberAttribute
, andDisplayAttribute
.
Enums.NET solves all of these issues and more.
Enums.NET Demo
using System;
using System.Linq;
using EnumsNET;
using NUnit.Framework;
using DescriptionAttribute = System.ComponentModel.DescriptionAttribute;
[TestFixture]
class EnumsNETDemo
{
// Enum definitions at bottom
[Test]
public void Enumerate()
{
var count = 0;
// Retrieves all enum members in increasing value order
foreach (var member in Enums.GetMembers<NumericOperator>())
{
NumericOperator value = member.Value;
string name = member.Name;
AttributeCollection attributes = member.Attributes;
++count;
}
Assert.AreEqual(8, count);
count = 0;
// Retrieves distinct values in increasing value order
foreach (var value in Enums.GetValues<NumericOperator>(EnumMemberSelection.Distinct))
{
string name = value.GetName();
AttributeCollection attributes = value.GetAttributes();
++count;
}
Assert.AreEqual(6, count);
}
[Test]
public void FlagEnumOperations()
{
// HasAllFlags
Assert.IsTrue((DaysOfWeek.Monday | DaysOfWeek.Wednesday | DaysOfWeek.Friday).HasAllFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));
Assert.IsFalse(DaysOfWeek.Monday.HasAllFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));
// HasAnyFlags
Assert.IsTrue(DaysOfWeek.Monday.HasAnyFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));
Assert.IsFalse((DaysOfWeek.Monday | DaysOfWeek.Wednesday).HasAnyFlags(DaysOfWeek.Friday));
// CombineFlags ~ bitwise OR
Assert.AreEqual(DaysOfWeek.Monday | DaysOfWeek.Wednesday, DaysOfWeek.Monday.CombineFlags(DaysOfWeek.Wednesday));
Assert.AreEqual(DaysOfWeek.Monday | DaysOfWeek.Wednesday | DaysOfWeek.Friday, FlagEnums.CombineFlags(DaysOfWeek.Monday, DaysOfWeek.Wednesday, DaysOfWeek.Friday));
// CommonFlags ~ bitwise AND
Assert.AreEqual(DaysOfWeek.Monday, DaysOfWeek.Monday.CommonFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));
Assert.AreEqual(DaysOfWeek.None, DaysOfWeek.Monday.CommonFlags(DaysOfWeek.Wednesday));
// RemoveFlags
Assert.AreEqual(DaysOfWeek.Wednesday, (DaysOfWeek.Monday | DaysOfWeek.Wednesday).RemoveFlags(DaysOfWeek.Monday));
Assert.AreEqual(DaysOfWeek.None, (DaysOfWeek.Monday | DaysOfWeek.Wednesday).RemoveFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));
// GetFlags, splits out the individual flags in increasing significance bit order
var flags = DaysOfWeek.Weekend.GetFlags();
Assert.AreEqual(2, flags.Count);
Assert.AreEqual(DaysOfWeek.Sunday, flags[0]);
Assert.AreEqual(DaysOfWeek.Saturday, flags[1]);
}
[Test]
public new void ToString()
{
// AsString, equivalent to ToString
Assert.AreEqual("Equals", NumericOperator.Equals.AsString());
Assert.AreEqual("-1", ((NumericOperator)(-1)).AsString());
// GetName
Assert.AreEqual("Equals", NumericOperator.Equals.GetName());
Assert.IsNull(((NumericOperator)(-1)).GetName());
// Get description
Assert.AreEqual("Is", NumericOperator.Equals.AsString(EnumFormat.Description));
Assert.IsNull(NumericOperator.LessThan.AsString(EnumFormat.Description));
// Get description if applied, otherwise the name
Assert.AreEqual("LessThan", NumericOperator.LessThan.AsString(EnumFormat.Description, EnumFormat.Name));
}
[Test]
public void Validate()
{
// Standard Enums, checks is defined
Assert.IsTrue(NumericOperator.LessThan.IsValid());
Assert.IsFalse(((NumericOperator)20).IsValid());
// Flag Enums, checks is valid flag combination or is defined
Assert.IsTrue((DaysOfWeek.Sunday | DaysOfWeek.Wednesday).IsValid());
Assert.IsFalse((DaysOfWeek.Sunday | DaysOfWeek.Wednesday | ((DaysOfWeek)(-1))).IsValid());
// Custom validation through IEnumValidatorAttribute<TEnum>
Assert.IsTrue(DayType.Weekday.IsValid());
Assert.IsTrue((DayType.Weekday | DayType.Holiday).IsValid());
Assert.IsFalse((DayType.Weekday | DayType.Weekend).IsValid());
}
[Test]
public void CustomEnumFormat()
{
EnumFormat symbolFormat = Enums.RegisterCustomEnumFormat(member => member.Attributes.Get<SymbolAttribute>()?.Symbol);
Assert.AreEqual(">", NumericOperator.GreaterThan.AsString(symbolFormat));
Assert.AreEqual(NumericOperator.LessThan, Enums.Parse<NumericOperator>("<", ignoreCase: false, symbolFormat));
}
[Test]
public void Attributes()
{
Assert.AreEqual("!=", NumericOperator.NotEquals.GetAttributes().Get<SymbolAttribute>().Symbol);
Assert.IsTrue(Enums.GetMember<NumericOperator>("GreaterThanOrEquals").Attributes.Has<PrimaryEnumMemberAttribute>());
Assert.IsFalse(NumericOperator.LessThan.GetAttributes().Has<DescriptionAttribute>());
}
[Test]
public void Parsing()
{
Assert.AreEqual(NumericOperator.GreaterThan, Enums.Parse<NumericOperator>("GreaterThan"));
Assert.AreEqual(NumericOperator.NotEquals, Enums.Parse<NumericOperator>("1"));
Assert.AreEqual(NumericOperator.Equals, Enums.Parse<NumericOperator>("Is", ignoreCase: false, EnumFormat.Description));
Assert.AreEqual(DaysOfWeek.Monday | DaysOfWeek.Wednesday, Enums.Parse<DaysOfWeek>("Monday, Wednesday"));
Assert.AreEqual(DaysOfWeek.Tuesday | DaysOfWeek.Thursday, FlagEnums.ParseFlags<DaysOfWeek>("Tuesday | Thursday", ignoreCase: false, delimiter: "|"));
}
enum NumericOperator
{
[Symbol("="), Description("Is")]
Equals,
[Symbol("!="), Description("Is not")]
NotEquals,
[Symbol("<")]
LessThan,
[Symbol(">="), PrimaryEnumMember] // PrimaryEnumMember indicates enum member as primary duplicate for extension methods
GreaterThanOrEquals,
NotLessThan = GreaterThanOrEquals,
[Symbol(">")]
GreaterThan,
[Symbol("<="), PrimaryEnumMember]
LessThanOrEquals,
NotGreaterThan = LessThanOrEquals
}
[AttributeUsage(AttributeTargets.Field)]
class SymbolAttribute : Attribute
{
public string Symbol { get; }
public SymbolAttribute(string symbol)
{
Symbol = symbol;
}
}
[Flags]
enum DaysOfWeek
{
None = 0,
Sunday = 1,
Monday = 2,
Tuesday = 4,
Wednesday = 8,
Thursday = 16,
Friday = 32,
Weekdays = Monday | Tuesday | Wednesday | Thursday | Friday,
Saturday = 64,
Weekend = Sunday | Saturday,
All = Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday
}
[Flags, DayTypeValidator]
enum DayType
{
Weekday = 1,
Weekend = 2,
Holiday = 4
}
[AttributeUsage(AttributeTargets.Enum)]
class DayTypeValidatorAttribute : Attribute, IEnumValidatorAttribute<DayType>
{
public bool IsValid(DayType value) => value.GetFlagCount(DayType.Weekday | DayType.Weekend) == 1 && FlagEnums.IsValidFlagCombination(value);
}
}
[Performance](performance.png)
Results from running the [PerformanceTestConsole](./Src/Enums.NET.PerfTestConsole/Program.cs) BenchmarkDotNet application.
Interface
See fuget for exploring the interface.
Credits
Inspired by Jon Skeet's Unconstrained Melody.
Uses Simon Cropp's Fody which is built on Jb Evain's Mono.Cecil for building the assembly.