sharpessentials.functions
1.2.20
See the version list below for details.
dotnet add package sharpessentials.functions --version 1.2.20
NuGet\Install-Package sharpessentials.functions -Version 1.2.20
<PackageReference Include="sharpessentials.functions" Version="1.2.20" />
<PackageVersion Include="sharpessentials.functions" Version="1.2.20" />
<PackageReference Include="sharpessentials.functions" />
paket add sharpessentials.functions --version 1.2.20
#r "nuget: sharpessentials.functions, 1.2.20"
#:package sharpessentials.functions@1.2.20
#addin nuget:?package=sharpessentials.functions&version=1.2.20
#tool nuget:?package=sharpessentials.functions&version=1.2.20
SharpEssentials
SharpEssentials is the ultimate C# utility library for .NET developers, helping you write cleaner, more efficient code with zero dependencies.
Table of Contents
Features
Core Utilities
- Argument Validation:
ThrowIfNull,ThrowIfEmpty,ThrowIfInvalid - Type Helpers: Safe casting, null coalescing, enum parsing
- Exception Handling: Retry policies, exception unwrapping
Collections & LINQ
Batch,DistinctBy,ToDictionarySafeForEachWithIndex,Shuffle,Paginate
Functional Programming
Option<T>,Result<T>,Either<L, R>- Pattern matching extensions
String Operations
- Truncation, formatting, validation
- Levenshtein distance, phonetic matching
DateTime Helpers
Async Utilities
SafeAwait()— await comConfigureAwait(false)de forma seguraEncadeamento
.Then(...)para fluidez e legibilidadeFireAndForgetSafe()com captura segura de exceçõesRastreamento de contexto com
AsyncTrackingContextExtensões para liberação manual de memória e descarte seguro
Analisador Roslyn
SNX001— detecta await semConfigureAwait(false)Business day calculations
Timezone conversions
Human-readable intervals ("2 hours ago")
Installation
Use your preferred .NET package manager:
# NuGet Package Manager
Install-Package SharpEssentials
# .NET CLI
dotnet add package SharpEssentials
# Paket CLI
paket add SharpEssentials
Compatibility: .NET 8.0+
Getting Started
using SharpEssentials;
// Validate arguments
order.ThrowIfNull(nameof(order));
// Batch operations
var batches = Enumerable.Range(1, 1000).Batch(100);
// Functional result handling
var result = Result.Try(ParseConfigFile);
result.Match(
success: config => Save(config),
failure: ex => Log.Error(ex)
);
Usage Examples
Retry Policy with Exponential Backoff
var data = await RetryPolicy
.WithExponentialBackoff(3, TimeSpan.FromSeconds(1))
.ExecuteAsync(() => FetchRemoteDataAsync());
String Helpers
var clean = " HELLO world ".TrimAll(); // "HELLO world"
var similarity = "color".SimilarityTo("colour"); // 0.91
Why Choose SharpEssentials?
| Metric | SharpEssentials | Alternatives |
|---|---|---|
| Performance | ⚡ Optimized | 🐢 Slower |
| Dependencies | 0 | 3+ |
| Maintenance | Active | Abandoned |
| Documentation | ✅ Comprehensive | Minimal |
- Battle-tested in production
- Consistent, intuitive API
- Detailed XML docs with examples
Documentation
Contributing
We welcome your contributions! Please:
- Fork the repo
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m "Add AmazingFeature") - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
git clone https://github.com/yourname/SharpEssentials.git
cd SharpEssentials
dotnet restore
dotnet build
dotnet test
Support & Community
- 📚 FAQ
- 🐛 Report Issues
- 💬 Join our Discord
- 📢 Follow us on Twitter and LinkedIn
License
Distributed under the MIT License. See LICENSE for details.
Thank you for choosing SharpEssentials! 🎉 Happy coding! 💻🚀
Async Toolkit Usage
SafeAwait
Use em todos os await dentro de serviços, repositórios, bibliotecas e APIs:
await _myService.ExecuteAsync().SafeAwait();
Encadeamento com .Then(...)
Permite uma escrita fluida e segura:
await _myRepo.GetDataAsync()
.Then(data => _processor.Process(data))
.Then(() => _logger.LogAsync("Finalizado"));
Fire-and-Forget seguro
Ideal para tarefas paralelas sem travar o thread principal:
_log.LogAsync("Background Start").FireAndForgetSafe(ex => Console.WriteLine($"Erro: {ex.Message}"));
Rastreamento com AsyncTrackingContext
Log com ContextId para cada requisição/processamento assíncrono:
using var ctx = AsyncTrackingContext.Start("SyncProducts");
_logger.LogInformation("[CTX:{ContextId}] Início", ctx.ContextId);
// ...
_logger.LogInformation("[CTX:{ContextId}] Fim", ctx.ContextId);
Liberação explícita de memória
var stream = new MemoryStream();
stream.ForceGC(); // Descarta e força GC
object? obj = new ExpensiveResource();
obj.DisposeAndCollect(); // Se for IDisposable, será descartado e coletado
Roslyn Analyzer
Incluímos um analisador estático que avisa sempre que um await estiver sem .ConfigureAwait(false):
Diagnóstico
SNX001: Use ConfigureAwait(false) para evitar problemas de contexto e deadlocks
Exemplo errado
await ProcessAsync(); // ⚠️ Gera alerta SNX001
Correto
await ProcessAsync().ConfigureAwait(false); // ✅
Como ativar
Adicione como referência de analisador em seu .csproj:
<ItemGroup>
<ProjectReference Include="..\SharpEssentials.Analyzer\SharpEssentials.Analyzer.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
| 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 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. |
-
net8.0
- BouncyCastle.Cryptography (>= 2.6.1)
- Microsoft.Extensions.Http.Polly (>= 9.0.7)
- Polly (>= 8.6.2)
- Polly.Extensions (>= 8.6.2)
- SixLabors.Fonts (>= 2.1.3)
- SixLabors.ImageSharp (>= 3.1.11)
- SixLabors.ImageSharp.Drawing (>= 2.1.7)
- System.Security.Cryptography.Xml (>= 9.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.22 | 297 | 10/28/2025 |
| 1.2.21 | 239 | 9/29/2025 |
| 1.2.20 | 191 | 9/29/2025 |
| 1.2.19 | 215 | 7/18/2025 |
| 1.2.18 | 197 | 7/14/2025 |
| 1.2.17 | 126 | 7/12/2025 |
| 1.2.16 | 211 | 6/23/2025 |
| 1.2.15 | 193 | 6/19/2025 |
| 1.2.14 | 181 | 6/19/2025 |
| 1.2.13 | 197 | 6/18/2025 |
| 1.2.12 | 196 | 6/16/2025 |
| 1.2.11 | 247 | 6/13/2025 |
| 1.2.10 | 239 | 6/8/2025 |
| 1.2.9 | 112 | 6/6/2025 |
| 1.2.8 | 259 | 5/23/2025 |
| 1.2.7 | 196 | 5/21/2025 |
| 1.2.6 | 191 | 5/21/2025 |
| 1.2.5 | 190 | 5/19/2025 |
| 1.2.4 | 179 | 5/19/2025 |
| 1.2.3 | 191 | 5/19/2025 |