Tooark.Enums 4.2.0

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

Tooark.Enums

Library that provides validated enumerated types, standardizing them for .NET projects. Includes methods to convert and validate enumerated values.

🌍 Languages: πŸ‡ΊπŸ‡Έ English (this file) Β· πŸ‡§πŸ‡· PortuguΓͺs

Contents

Installation

dotnet add package Tooark.Enums

The package has no configuration: the enumerators are static values, used directly.

How they work

The three types are classes with static instances, not C# enums. That lets each value carry more than a number β€” description, format pattern, validation function β€” at the cost of not being usable as attribute arguments, which require constants.

All of them expose the same set of operations:

Operation Behavior
ToString() Returns the description
ToInt() Returns the id
implicit (int) Same as ToInt()
implicit (string) Same as ToString()
implicit int β†’ enum Resolves by id
implicit string β†’ enum Resolves by description, ignoring case and leading/trailing whitespace

Two rules apply to all three:

  • The description is normalized. "aws", "AWS" and " Aws " resolve to the same value.
  • An unrecognized id or description resolves to the neutral value β€” None in ECloudProvider and EDocumentType, Unknown in EFileType β€”, which is the member meant for that. Converting a null instance to int or string, on the other hand, throws InternalServerErrorException with Invalid.Parameter;null: there is no correct id or description to return, and returning zero would be making data up.

Enumerators

1. Cloud Provider

Purpose: represents the supported cloud providers.

Value Id Description Also accepts
None 0 None β€”
Amazon 1 AWS Amazon
Google 2 GCP Google
Microsoft 3 Azure Microsoft

Usage Example

2. Document Type

Purpose: represents the document types, each with its own format and check.

Value Id Check
None 0 Accepts any document
CPF 1 Format and check digits
RG 2 Format and check digit, when provided
CNH 3 Format and check digits
CNPJ 4 Format and check digits, accepts the alphanumeric CNPJ
CPF_CNPJ 5 CPF or CNPJ, both with check digits
CPF_RG 6 CPF or RG
CPF_RG_CNH 7 CPF, RG or CNH

Own methods:

  • ToRegex(): returns the format pattern of the document type.
  • IsValid: function that verifies the check digits, accepting the value with or without mask.

The two checks are distinct layers that complement each other: ToRegex() handles the shape and IsValid handles the content. A complete validation applies both, as the Document value object in Tooark.ValueObjects and the DocumentValidationAttribute in Tooark.Attributes do. Called on its own, IsValid accepts 529.982.247-25 and 52998224725 alike, and never throws for invalid input β€” it returns false.

The digit calculation comes from DocumentDigit, in Tooark.Validations, the same one used by that package's validations β€” so new Validation().IsCpf(...) and EDocumentType.CPF.IsValid(...) always agree.

Usage Example

3. File Type

Purpose: represents the file categories.

Value Id Description
Unknown 0 Unknown
Document 1 Document
Image 2 Image
Video 3 Video
Audio 4 Audio

Usage Example

Usage Examples

Cloud Provider

using Tooark.Enums;

ECloudProvider provider = ECloudProvider.Amazon;

Console.WriteLine(provider.ToString()); // AWS
Console.WriteLine(provider.ToInt());    // 1

// Implicit conversions, handy to persist and read back
int id = provider;                      // 1
string description = provider;          // "AWS"

// The description is case-insensitive
ECloudProvider fromConfiguration = "aws";  // Amazon
ECloudProvider fromDatabase = 1;           // Amazon

Document Type

using Tooark.Enums;

EDocumentType docType = EDocumentType.CPF;

Console.WriteLine(docType.ToString()); // CPF
Console.WriteLine(docType.ToInt());    // 1
Console.WriteLine(docType.ToRegex());  // ^\d{3}\.\d{3}\.\d{3}-\d{2}$

// IsValid verifies the digits, with or without mask
Console.WriteLine(docType.IsValid("529.982.247-25")); // True
Console.WriteLine(docType.IsValid("52998224725"));    // True
Console.WriteLine(docType.IsValid("529.982.247-24")); // False

Complete validation, applying format and digits:

using System.Text.RegularExpressions;
using Tooark.Enums;

bool IsValidDocument(string document, EDocumentType type) =>
  Regex.IsMatch(document, type.ToRegex()) && type.IsValid(document);

File Type

using Tooark.Enums;

EFileType fileType = EFileType.Image;

Console.WriteLine(fileType.ToString()); // Image
Console.WriteLine(fileType.ToInt());    // 2

// An unrecognized value resolves to Unknown
EFileType unknown = "spreadsheet";      // Unknown

Dependencies

Dependency Version Usage
Tooark.Validations 4.x DocumentDigit and the format patterns
Tooark.Exceptions 4.x Null-instance conversion error

Contributing

Contributions are welcome! Feel free to open issues and pull requests in the Tooark.Enums repository.

License

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.

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 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.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Tooark.Enums:

Package Downloads
Tooark.ValueObjects

Package for managing predefined and validated Value Objects for .NET applications.

Tooark.Entities

Package for managing base entities in .NET applications.

Tooark.Attributes

Package for creating attribute validators for .NET applications.

Tooark

Package with all Tooark resources for .NET applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.7.1 67 10/17/2026
4.7.0 354 9/30/2026
4.6.0 185 9/29/2026
4.5.0 151 9/29/2026
4.4.0 149 9/28/2026
4.3.0 162 9/26/2026
4.2.1 160 9/25/2026
4.2.0 170 9/20/2026
4.1.0 167 9/18/2026
4.0.1 231 8/25/2026
4.0.0 180 8/25/2026
3.3.6 154 9/18/2026
3.3.5 168 8/25/2026
3.3.4 349 8/12/2026
3.3.3 425 7/27/2026
3.3.2 373 6/11/2026
3.3.1 213 6/6/2026
2.3.5 147 9/18/2026
2.3.4 178 8/25/2026
2.3.3 184 7/27/2026
Loading failed