Woqqa.Enum2String 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Woqqa.Enum2String --version 1.0.0
                    
NuGet\Install-Package Woqqa.Enum2String -Version 1.0.0
                    
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="Woqqa.Enum2String" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Woqqa.Enum2String" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Woqqa.Enum2String" />
                    
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 Woqqa.Enum2String --version 1.0.0
                    
#r "nuget: Woqqa.Enum2String, 1.0.0"
                    
#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 Woqqa.Enum2String@1.0.0
                    
#: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=Woqqa.Enum2String&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Woqqa.Enum2String&version=1.0.0
                    
Install as a Cake Tool

Enum 2 String


Description

Enum2String is a minimalistic library that provides a simple yet powerful way to define custom string representations for enum values. With a single attribute and extension methods, you can easily map enum values to display names, localization strings, or any custom text representation.


Guide

  1. Enum string mapping
enum SomeEnum
{
    first, // There is - first

    [AsString()] // AsString() → "none"
    second,

    [AsString("Third element")] // AsString() → "Third element"
    third
}
  1. String get
AsString() and AsStringAttribute guide:
  • The AsStringAttribute has 2 constructors: one with a value parameter and one without. If no value is provided, "none" will be used.
  • The AsString() method returns the value set via AsStringAttribute or the raw field name from the enum.
enum Role
{
    User,
    [AsString()]
    Moder,
    [AsString("Administrator")]
    Admin
}

var user = Role.User;
var moder = Role.Moder;
var admin = Role.Admin;

Console.WriteLine(user.AsString()); // User
Console.WriteLine(moder.AsString()); // none
Console.WriteLine(admin.AsString()); // Administrator
HasString() guide:
  • The HasString() method returns:
    • true if the value was set using AsStringAttribute.
    • false if the value was not set.
enum SomeEnum
{
    first,

    [AsString("2nd element")]
    second,

    third
}

bool f = SomeEnum.first.HasString(); //false
bool f = SomeEnum.second.HasString(); //true
bool f = SomeEnum.third.HasString(); //false
TryAsString() guide:
  • The TryAsString(out string name) method returns:
    • true if the value was set using AsStringAttribute.
    • false if it was not set. Additionally, it writes the AsStringAttribute value to the out string name parameter.
enum Settings
{
    [AsString()]
    Low,

    [AsString("Medium graphic")]
    Medium,

    High
}

bool low = Settings.Low.TryAsString(out string low_name);
bool mid = Settings.Medium.TryAsString(out string mid_name);
bool high = Settings.High.TryAsString(out string high_name);

/*
low is true
mid is true
high is false

low_name is "none"
mid_name is "Medium graphic"
high_name is "High"
*/ 

Installation

  • .NET CLI:
dotnet add package Woqqa.Enum2String --version 1.0.0
  • Package Manager:
Install-Package Woqqa.Enum2String
  • Reference:
<PackageReference Include="Woqqa.Enum2String" Version="1.0.0" />
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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 106 2/4/2026
2.2.2 103 1/5/2026
2.2.1 98 1/5/2026
2.2.0 99 1/2/2026
2.1.0 100 1/1/2026
2.0.0 100 1/1/2026
1.0.0 181 12/22/2025