Tooark.Enums
4.2.0
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
<PackageReference Include="Tooark.Enums" Version="4.2.0" />
<PackageVersion Include="Tooark.Enums" Version="4.2.0" />
<PackageReference Include="Tooark.Enums" />
paket add Tooark.Enums --version 4.2.0
#r "nuget: Tooark.Enums, 4.2.0"
#:package Tooark.Enums@4.2.0
#addin nuget:?package=Tooark.Enums&version=4.2.0
#tool nuget:?package=Tooark.Enums&version=4.2.0
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
- How they work
- ECloudProvider
- EDocumentType
- EFileType
- Usage Examples
- Dependencies
- Contributing
- License
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 β
NoneinECloudProviderandEDocumentType,UnknowninEFileTypeβ, which is the member meant for that. Converting a null instance tointorstring, on the other hand, throwsInternalServerErrorExceptionwithInvalid.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 |
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 andIsValidhandles the content. A complete validation applies both, as theDocumentvalue object inTooark.ValueObjectsand theDocumentValidationAttributeinTooark.Attributesdo. Called on its own,IsValidaccepts529.982.247-25and52998224725alike, and never throws for invalid input β it returnsfalse.
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.
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 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 | Versions 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. |
-
net10.0
- Tooark.Exceptions (>= 4.2.0)
- Tooark.Validations (>= 4.2.0)
-
net8.0
- Tooark.Exceptions (>= 4.2.0)
- Tooark.Validations (>= 4.2.0)
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 |