pvNugsEnumConvNc9 9.0.1

dotnet add package pvNugsEnumConvNc9 --version 9.0.1
                    
NuGet\Install-Package pvNugsEnumConvNc9 -Version 9.0.1
                    
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="pvNugsEnumConvNc9" Version="9.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="pvNugsEnumConvNc9" Version="9.0.1" />
                    
Directory.Packages.props
<PackageReference Include="pvNugsEnumConvNc9" />
                    
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 pvNugsEnumConvNc9 --version 9.0.1
                    
#r "nuget: pvNugsEnumConvNc9, 9.0.1"
                    
#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 pvNugsEnumConvNc9@9.0.1
                    
#: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=pvNugsEnumConvNc9&version=9.0.1
                    
Install as a Cake Addin
#tool nuget:?package=pvNugsEnumConvNc9&version=9.0.1
                    
Install as a Cake Tool

Here's the complete content in a single code block, making it easier to copy:

pvNugsEnumConvNc9

A .NET utility library that provides enhanced enum conversion capabilities, focusing on Description attribute-based conversions and flexible matching strategies.

Features

  • Extract codes from enum Description attributes
  • Convert string codes back to enum values
  • Support for multiple codes per enum value (comma-separated in Description)
  • Case-insensitive matching by default
  • Custom matching strategy support
  • Default value fallback support

Installation

Install the package via NuGet:

shell
dotnet add package pvNugsEnumConvNc9

Usage

Basic Usage

csharp
// Define an enum with Description attributes
public enum Status
{
[Description("A")]
Active,

    [Description("I")]
    Inactive,
    
    [Description("P,PEND")]  // Multiple codes
    Pending
}

// Get code from enum value
string code = Status.Active.GetCode();  // Returns "A"

// Convert code back to enum
Status status = EnumConvert.GetValue<Status>("A", Status.Inactive);  // Returns Status.Active

Multiple Codes Support

The library supports multiple codes in the Description attribute, separated by commas. The first code is considered the primary code:

csharp
Status pending = EnumConvert.GetValue<Status>("PEND", Status.Active);  // Returns Status.Pending

Custom Matching

You can provide your own matching strategy:

csharp
bool CustomMatcher(string x, string y) => x.StartsWith(y);
Status status = EnumConvert.GetValue("PEN", Status.Active, CustomMatcher);  // Returns Status.Pending

Error Handling

  • ArgumentNullException: Thrown when the provided code is null or empty
  • ArgumentOutOfRangeException: Thrown when:
    • No matching enum value is found for the provided code
    • An enum value lacks a Description attribute

Requirements

  • .NET 9.0 or higher
  • C# 13.0 or higher

License

[License details should be added here]

Contributing

[Contributing guidelines should be added here]

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 was computed.  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.
  • net9.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on pvNugsEnumConvNc9:

Package Downloads
pvNugsLoggerNc9Abstractions

Package Description

pvNugsLoggerNc9

Package Description

pvNugsLoggerNc9ResWrapper

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.1 266 8/27/2025
9.0.0 199 8/27/2025
1.0.0 181 8/27/2025

Initial