ToolBX.DescriptiveEnums 3.0.0

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

DescriptiveEnums

DescriptiveEnums

Adds a [Description("Text")] attribute that you can use on enum values and get using the GetDescription method in order to return better-formatted strings than a simple ToString() would.

Getting started

public enum MyEnum
{
	[Description("First value")]
	Value1,
	[Description("Second value")]
	Value2,
	[Description("Third value")]
	Value3
}
public void Method(MyEnum value)
{
	//Will return the string of text that is in the enum's [Description] attribute
	var description = value.GetDescription();
	...
	//You can also use TryGetDescription which will never throw an exception and return the enum's ToString() result if it has no [Description]
	var description2 = value.TryGetDescription();
}
public void Method(MyEnum? value)
{
	//Nullable enums are also supported and are used in the exact same way though bear in mind that null enums will throw an exception
	var description = value.GetDescription();
	...
	//Will not throw an exception if it's null. It will return an empty string instead
	var description2 = value.TryGetDescription();
}

Undefined values

public void Method(MyEnum value)
{
	//What if some bozo tries to pass something like (MyEnum)-8 for which there is no enum member defined?
	value.ThrowIfUndefined(); //Will throw something along the lines of "Value '-8' is undefined for enum 'MyEnum'"

	//Or you can do this if you don't like the above default message
	value.ThrowIfUndefined("Better message!");
}
public MyEnum Value
{
	get => _value;
	//You can also inline it in a set like so
	init => _value = value.ThrowIfUndefined();
}
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.  net9.0 was computed.  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.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ToolBX.DescriptiveEnums:

Package Downloads
ToolBX.FileGuy

High-level API for handling files.

ToolBX.MetaQuery

Queries which can be used in visual scripting in a frontend and translated to good old LINQ in a backend.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 465 9/26/2024
3.0.0-beta1 116 9/23/2024
2.2.0 561 1/12/2024
2.2.0-beta1 253 11/21/2023
2.0.4 2,148 4/25/2023
2.0.3 289 2/10/2023
2.0.2 296 2/9/2023
2.0.1 297 2/9/2023
2.0.0 391 11/9/2022
2.0.0-beta1 165 10/12/2022
1.0.0 418 10/12/2022