Carubbi.Extensions 2.0.0

dotnet add package Carubbi.Extensions --version 2.0.0
                    
NuGet\Install-Package Carubbi.Extensions -Version 2.0.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="Carubbi.Extensions" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Carubbi.Extensions" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Carubbi.Extensions" />
                    
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 Carubbi.Extensions --version 2.0.0
                    
#r "nuget: Carubbi.Extensions, 2.0.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 Carubbi.Extensions@2.0.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=Carubbi.Extensions&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Carubbi.Extensions&version=2.0.0
                    
Install as a Cake Tool

Carubbi.Extensions

NuGet NuGet downloads CI

A simple extension-method library that solves common tasks. Built for .NET 10.

Features

  • Type conversion: forgiving, culture-invariant parsing to any value type or enum
  • Enum helpers: descriptions, flags operations, data sources for dropdowns
  • Brazilian documents: CPF/CNPJ validation and manipulation, CNAE code parsing
  • MIME types: resolve a MIME type from any file extension (500+ mappings)
  • Stream utilities: read any stream (seekable or not) into a byte array
  • Reflection helpers: get/set properties, invoke methods (including generic ones)
  • Image helpers (Windows only): bitmap ↔ byte array conversions and cropping

Installation

dotnet add package Carubbi.Extensions

Usage

Type conversion

Rather than:

int? intVariable;
try
{
    intVariable = Convert.ToInt32(str);
}
catch (Exception)
{
    intVariable = defaultValue;
}

or:

if (!int.TryParse(str, out int intValue))
{
    intValue = defaultValue;
}

you just write:

int? intVariable = str.To<int>();
int intVariableWithDefault = str.To(defaultValue: -1);
DayOfWeek day = "saturday".To<DayOfWeek>(); // enums are case-insensitive
bool enabled = "sim".To<bool>(); // legacy truthy tokens: 1, on, yes, sim, sucesso, success

Parsing always uses the invariant culture, so "1.5".To<double>() is 1.5 regardless of the machine's regional settings.

Brazilian documents (CPF / CNPJ / CNAE)

bool validCpf = "529.982.247-25".IsCpf();          // true
bool validCnpj = "11.222.333/0001-81".IsCnpj();    // true

string full = "112223330001".CompleteCheckDigits(); // "11222333000181"
string hq = "11222333".GetHeadquarters();           // root + 0001 + check digits
bool isHq = "11222333000181".IsHeadquarters();      // suffix 0001?
long number = "11.222.333/0001-81".ToLong();        // 11222333000181

var (code, letter) = ("0111-3/01".ParseCnae());     // code=111301, letter=""

Enum helpers

enum Priority { [Description("Urgent")] High, Low }

string text = Priority.High.Text();                 // "Urgent" (falls back to the member name)
var pairs = default(Priority).ToDataSource<Priority>(); // ordered key/value pairs for UIs

MIME types

string mime = ".pdf".GetMimeType();       // application/pdf
string fallback = ".whoami".GetMimeType(); // application/octet-stream

Streams, reflection and images

byte[] bytes = someStream.ToByteArray();          // works with non-seekable streams too

obj.SetProperty("Name", "Alice");                  // reflection by name
int value = obj.Call<int>("Sum", 2, 3);            // method invocation by name
obj.CallGeneric(typeof(int), "Echo", 42);          // generic method invocation

byte[] cropped = bitmap.Crop(new Rectangle(0, 0, 50, 50)); // Windows only
ImageFormat format = image.GetImageFormat();

The BitmapExtensions and ImageExtensions classes rely on GDI+ (System.Drawing.Common) and are supported on Windows only.

Building and testing locally

Prerequisites:

  • .NET SDK 10 (global.json pins the minimum version)
  • Windows (the test suite covers the GDI+ based image extensions)
dotnet build -c Release
dotnet test Carubbi.Extensions.sln -c Release

Releasing

Pushing a tag v* (for example v2.0.0) triggers the publish workflow, which builds in Release mode, packs the library and publishes it to nuget.org using GitHub Actions trusted publishing.

Product Compatible and additional computed target framework versions.
.NET 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 (7)

Showing the top 5 NuGet packages that depend on Carubbi.Extensions:

Package Downloads
Carubbi.ObjectXMFDisplay

Simulador de Emulador de Terminal Mainframe baseado na interface do Microfocus Rumba

Carubbi.Google.TTS

Google Text-to-speech proxy

Carubbi.Mainframe

Wrapper de Emulador de Terminal Mainframe Microfocus Rumba

Carubbi.CaptchaBreaker

Wrapper do Tesseract e do Captcha Breaker para quebra de captchas

Carubbi.Mailer.Outlook2010

Email sending and receiving through the locally installed Outlook client (COM interop). Requires Microsoft Office with Outlook at runtime.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 137 8/26/2026
1.2.3 2,179 11/4/2018
1.2.2 1,600 9/10/2018
1.2.1 1,044 9/10/2018
1.2.0 1,039 9/10/2018
1.1.0 2,219 8/30/2018
1.0.0 3,345 8/20/2018