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
                    
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="FGV.Lib.Helpers" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FGV.Lib.Helpers" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="FGV.Lib.Helpers" />
                    
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 FGV.Lib.Helpers --version 1.1.0
                    
#r "nuget: FGV.Lib.Helpers, 1.1.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 FGV.Lib.Helpers@1.1.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=FGV.Lib.Helpers&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=FGV.Lib.Helpers&version=1.1.0
                    
Install as a Cake Tool

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

  1. Clone this repository
  2. Add a reference to the FGV.Lib.Helpers project in your solution
  3. Build and use

Components

ObjectConverter

Provides methods for converting objects between different types:

  • CastModel<T>() - Cast an object to a specific type
  • ConvertTo<T>() - Convert a collection of objects to a collection of a specific type
  • ConvertDataTableToList<T>() - Convert a DataTable to a typed list
  • SetValue() - 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 hash
  • CreateCodErro() - Create an error code
  • CreatePin() - Generate a PIN
  • LerDadosArquivo() - Read file data
  • ObterListaEstado() - Get list of Brazilian states
  • ObterAreaFormacao() - Get list of educational areas
  • ObterPaises() - Get list of countries
  • ValorEmReal() - 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 CPF
  • ValidarCNPJ() - Validate Brazilian CNPJ
  • ValidarNIS() - Validate Brazilian NIS
  • ValidarEmail() - Validate email address
  • ValidarTelefone() - Validate phone number
  • ValidarSenha() - Validate password
  • ValidarData() - Validate date
  • ValidarArquivo() - 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 format
  • IsBetween() - 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 uppercase
  • CaixaBaixa() - Convert to lowercase
  • Capitalizar() - Capitalize the first letter of each word
  • FormatarCpf() - Format CPF
  • FormatarCnpj() - Format CNPJ
  • RemoverAscento() - Remove accents
  • SomenteNumeros() - 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
1.1.0 581 6/5/2025
1.0.0 727 5/28/2025