RD.Extensions.Enum 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package RD.Extensions.Enum --version 1.0.2
NuGet\Install-Package RD.Extensions.Enum -Version 1.0.2
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="RD.Extensions.Enum" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RD.Extensions.Enum --version 1.0.2
#r "nuget: RD.Extensions.Enum, 1.0.2"
#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.
// Install RD.Extensions.Enum as a Cake Addin
#addin nuget:?package=RD.Extensions.Enum&version=1.0.2

// Install RD.Extensions.Enum as a Cake Tool
#tool nuget:?package=RD.Extensions.Enum&version=1.0.2

RD.Extensions.Enums

This project provides a set of utilities to work with enums in .NET. It includes methods for retrieving various types of values (string, integer, double, etc.) from enum values. Also it caches the values for better performance.

Installation

Install the nuget package RD.Extensions.Enums from nuget.org.

Usage

enum MyEnum 
{
	[StringValue("Value1")]
	[IntegerValue(1)]
	[LongValue(1)]
	[DoubleValue(5.5)]
	[BooleanValue(true)]
	[KeyValuePair("keyOne", "valueOne")]
	[KeyValuePair("keyTwo", "valueTwo")]
	MyValue
}

IEnumCache enumCache = new EnumCache();

enumCache.GetStringValue(MyEnum.MyValue); // returns "Value1"
enumCache.GetIntegerValue(MyEnum.MyValue); // returns 1
enumCache.GetLongValue(MyEnum.MyValue); // returns 1
enumCache.GetDoubleValue(MyEnum.MyValue); // returns 5.5
enumCache.GetBooleanValue(MyEnum.MyValue); // returns true
enumCache.GetKeyValuePairs(MyEnum.MyValue); // returns a List<KeyValuePair<string, object>>
enumCache.GetEnumValueByAttributeValue<MyEnum, string>("Value1"); // returns MyEnum.MyValue

Caching Mechanism

The EnumCache class uses a caching mechanism to improve performance when retrieving values associated with an Enum. The first time a value is retrieved for a particular Enum, it is store in a cache. Subsequent requests for the same value are then served from the cache.

When retrieving a single value from an enum, only the value will be cached. It is also possible to cache the entire enum by calling the CacheEnum method.

Contributing

If you want to contribute to this project, please create a pull request with your changes.

License

The project is licensed under the MIT license. You can find the license here.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on RD.Extensions.Enum:

Package Downloads
RD.TMDB.Client

TMDB API Wrapper for .NET

RD.MediaInfo

Simple and lightweight .NET Wrapper for MediaInfo

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 180 4/22/2024
1.0.3 84 4/22/2024
1.0.2 95 4/16/2024
1.0.0 79 4/16/2024

Added a method to search enum values by their attribute values.