Carubbi.Extensions
2.0.0
dotnet add package Carubbi.Extensions --version 2.0.0
NuGet\Install-Package Carubbi.Extensions -Version 2.0.0
<PackageReference Include="Carubbi.Extensions" Version="2.0.0" />
<PackageVersion Include="Carubbi.Extensions" Version="2.0.0" />
<PackageReference Include="Carubbi.Extensions" />
paket add Carubbi.Extensions --version 2.0.0
#r "nuget: Carubbi.Extensions, 2.0.0"
#:package Carubbi.Extensions@2.0.0
#addin nuget:?package=Carubbi.Extensions&version=2.0.0
#tool nuget:?package=Carubbi.Extensions&version=2.0.0
Carubbi.Extensions
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
BitmapExtensionsandImageExtensionsclasses rely on GDI+ (System.Drawing.Common) and are supported on Windows only.
Building and testing locally
Prerequisites:
- .NET SDK 10 (
global.jsonpins 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 | Versions 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. |
-
net10.0
- System.Drawing.Common (>= 10.0.11)
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.