ToolBX.DescriptiveEnums
2.2.0-beta1
This is a prerelease version of ToolBX.DescriptiveEnums.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ToolBX.DescriptiveEnums --version 2.2.0-beta1
NuGet\Install-Package ToolBX.DescriptiveEnums -Version 2.2.0-beta1
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-beta1" />
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-beta1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ToolBX.DescriptiveEnums, 2.2.0-beta1"
#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-beta1&prerelease // Install ToolBX.DescriptiveEnums as a Cake Tool #tool nuget:?package=ToolBX.DescriptiveEnums&version=2.2.0-beta1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions 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. 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. |
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 |
---|---|---|
3.0.0 | 382 | 9/26/2024 |
3.0.0-beta1 | 104 | 9/23/2024 |
2.2.0 | 549 | 1/12/2024 |
2.2.0-beta1 | 244 | 11/21/2023 |
2.0.4 | 2,107 | 4/25/2023 |
2.0.3 | 249 | 2/10/2023 |
2.0.2 | 253 | 2/9/2023 |
2.0.1 | 257 | 2/9/2023 |
2.0.0 | 349 | 11/9/2022 |
2.0.0-beta1 | 122 | 10/12/2022 |
1.0.0 | 374 | 10/12/2022 |