pvNugsEnumConvNc9 9.0.0
See the version list below for details.
dotnet add package pvNugsEnumConvNc9 --version 9.0.0
NuGet\Install-Package pvNugsEnumConvNc9 -Version 9.0.0
<PackageReference Include="pvNugsEnumConvNc9" Version="9.0.0" />
<PackageVersion Include="pvNugsEnumConvNc9" Version="9.0.0" />
<PackageReference Include="pvNugsEnumConvNc9" />
paket add pvNugsEnumConvNc9 --version 9.0.0
#r "nuget: pvNugsEnumConvNc9, 9.0.0"
#:package pvNugsEnumConvNc9@9.0.0
#addin nuget:?package=pvNugsEnumConvNc9&version=9.0.0
#tool nuget:?package=pvNugsEnumConvNc9&version=9.0.0
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 emptyArgumentOutOfRangeException
: 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 | Versions 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. |
-
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.
Initial