FGV.Lib.Helpers
1.1.0
dotnet add package FGV.Lib.Helpers --version 1.1.0
NuGet\Install-Package FGV.Lib.Helpers -Version 1.1.0
<PackageReference Include="FGV.Lib.Helpers" Version="1.1.0" />
<PackageVersion Include="FGV.Lib.Helpers" Version="1.1.0" />
<PackageReference Include="FGV.Lib.Helpers" />
paket add FGV.Lib.Helpers --version 1.1.0
#r "nuget: FGV.Lib.Helpers, 1.1.0"
#:package FGV.Lib.Helpers@1.1.0
#addin nuget:?package=FGV.Lib.Helpers&version=1.1.0
#tool nuget:?package=FGV.Lib.Helpers&version=1.1.0
FGV.Lib.Helpers
A comprehensive .NET 7.0 utility library providing various helper methods and extensions to simplify common development tasks in FGV projects. This library offers a collection of reusable components for validation, conversion, string manipulation, QR code generation, and more.
Features
- Object conversion and type casting
- QR code generation
- String manipulation and formatting
- Date and time utilities
- Validation for Brazilian documents (CPF, CNPJ, NIS)
- Email, phone, and password validation
- Custom exceptions for better error handling
- Various utility methods for common tasks
Installation
Via NuGet Package Manager
Install-Package FGV.Lib.Helpers
Via .NET CLI
dotnet add package FGV.Lib.Helpers
Manual Installation
- Clone this repository
- Add a reference to the FGV.Lib.Helpers project in your solution
- Build and use
Components
ObjectConverter
Provides methods for converting objects between different types:
CastModel<T>()
- Cast an object to a specific typeConvertTo<T>()
- Convert a collection of objects to a collection of a specific typeConvertDataTableToList<T>()
- Convert a DataTable to a typed listSetValue()
- Set property values with type conversion
// Example: Convert from one model to another
var sourceModel = new SourceModel { Name = "John", Age = 30 };
var targetModel = ObjectConverter.CastModel<TargetModel>(sourceModel);
// Example: Convert DataTable to list of objects
var people = ObjectConverter.ConvertDataTableToList<Person>(dataTable);
QrCodeHelper
Generates QR codes from URLs:
// Generate a QR code for a URL
string base64QrCode = QrCodeHelper.GerarQrCode("https://example.com");
// Use in an HTML img tag
// <img src="data:image/png;base64,@base64QrCode" />
Utils
A collection of utility methods:
GerarHashB64()
- Generate a Base64 hashCreateCodErro()
- Create an error codeCreatePin()
- Generate a PINLerDadosArquivo()
- Read file dataObterListaEstado()
- Get list of Brazilian statesObterAreaFormacao()
- Get list of educational areasObterPaises()
- Get list of countriesValorEmReal()
- Format currency in Brazilian Real
// Generate a 6-digit PIN
string pin = Utils.CreatePin(6);
// Format value as Brazilian Real
string formattedValue = Utils.ValorEmReal(1250.75); // R$ 1.250,75
Validacoes
Methods for data validation:
ValidarCPF()
- Validate Brazilian CPFValidarCNPJ()
- Validate Brazilian CNPJValidarNIS()
- Validate Brazilian NISValidarEmail()
- Validate email addressValidarTelefone()
- Validate phone numberValidarSenha()
- Validate passwordValidarData()
- Validate dateValidarArquivo()
- Validate file size and extension
// Validate a CPF
bool isCpfValid = Validacoes.ValidarCPF("123.456.789-09");
// Validate an email
bool isEmailValid = Validacoes.ValidarEmail("user@example.com");
// Validate a password
bool isPasswordValid = Validacoes.ValidarSenha("P@ssw0rd", 8);
Extensions
DateTimeExtensions
ToDateTimeBR()
- Format DateTime to Brazilian formatIsBetween()
- Check if a date is between two dates
DateTime date = DateTime.Now;
string formattedDate = date.ToDateTimeBR();
bool isInRange = date.IsBetween(startDate, endDate);
StringExtensions
CaixaAlta()
- Convert to uppercaseCaixaBaixa()
- Convert to lowercaseCapitalizar()
- Capitalize the first letter of each wordFormatarCpf()
- Format CPFFormatarCnpj()
- Format CNPJRemoverAscento()
- Remove accentsSomenteNumeros()
- Get only numbers from a string
string text = "exemplo de texto";
string capitalized = text.Capitalizar(); // "Exemplo De Texto"
string cpf = "12345678909";
string formattedCpf = cpf.FormatarCpf(); // "123.456.789-09"
string withAccents = "ação";
string withoutAccents = withAccents.RemoverAscento(); // "acao"
Exceptions
CustomException
A base exception class for custom exceptions.
NotFoundException
Exception for when a resource is not found.
ValidacaoException
Exception for validation errors that can contain a list of error messages.
// Throw a validation exception
if (!isValid)
{
throw new ValidacaoException("Validation failed", new List<string> { "Field1 is required", "Field2 is invalid" });
}
// Throw a not found exception
if (user == null)
{
throw new NotFoundException("User not found");
}
Requirements
- .NET 7.0 or higher
- Dependencies:
- FluentValidation
- HtmlSanitizer
- HttpExtension
- QRCoder
License
This project is licensed under the MIT License.
Contributing
Contributions are welcome. Please feel free to submit a Pull Request.
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. 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. |
-
net7.0
- FluentValidation (>= 11.9.0)
- HtmlSanitizer (>= 8.0.746)
- HttpExtension (>= 4.0.0)
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
- QRCoder (>= 1.4.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on FGV.Lib.Helpers:
Package | Downloads |
---|---|
FGV.Lib.Api
Package Description |
|
FGV.Lib.Persistence.MongoDb
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.