ToolBX.DescriptiveEnums 2.2.0

dotnet add package ToolBX.DescriptiveEnums --version 2.2.0
NuGet\Install-Package ToolBX.DescriptiveEnums -Version 2.2.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="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToolBX.DescriptiveEnums --version 2.2.0
#r "nuget: ToolBX.DescriptiveEnums, 2.2.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.
// Install ToolBX.DescriptiveEnums as a Cake Addin
#addin nuget:?package=ToolBX.DescriptiveEnums&version=2.2.0

// Install ToolBX.DescriptiveEnums as a Cake Tool
#tool nuget:?package=ToolBX.DescriptiveEnums&version=2.2.0

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 net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.
  • net7.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
2.2.0 349 1/12/2024
2.2.0-beta1 156 11/21/2023
2.0.4 2,079 4/25/2023
2.0.3 222 2/10/2023
2.0.2 225 2/9/2023
2.0.1 229 2/9/2023
2.0.0 319 11/9/2022
2.0.0-beta1 109 10/12/2022
1.0.0 347 10/12/2022