ClearTools 3.2.0
dotnet add package ClearTools --version 3.2.0
NuGet\Install-Package ClearTools -Version 3.2.0
<PackageReference Include="ClearTools" Version="3.2.0" />
<PackageVersion Include="ClearTools" Version="3.2.0" />
<PackageReference Include="ClearTools" />
paket add ClearTools --version 3.2.0
#r "nuget: ClearTools, 3.2.0"
#:package ClearTools@3.2.0
#addin nuget:?package=ClearTools&version=3.2.0
#tool nuget:?package=ClearTools&version=3.2.0
ClearTools
A comprehensive .NET Standard 2.1 utility library providing robust, production-ready tools for common development tasks. ClearTools offers utilities for string manipulation, cryptography, image processing, Azure services integration, HTTP client operations, and much more.
🚀 Quick Start
Installation
dotnet add package ClearTools
Basic Usage
using ClearTools.Extensions;
using Clear.Tools;
// String extensions
string text = "Hello 123 World!";
int number = text.ToInt32(); // Extracts numbers: 123
string cleaned = StringUtility.StripSymbols(text); // Removes symbols, preserves spaces: "Hello 123 World"
// Image processing
var scaledImage = ImageUtility.ScaleImage(originalImage, 800, 600);
// Cryptography
string salt = Crypto.CreateSalt();
string hash = Crypto.EncodeSHA256("password", salt);
// OTP generation
var otpResult = OtpUtility.GenerateCode("user@example.com", 12345, TimeSpan.FromMinutes(5));
📋 Table of Contents
- Core Utilities
- Extension Methods
- Azure Integration
- HTTP Client
- Middleware
- Data Models
- Installation & Setup
- Examples
- Documentation
- Contributing
- License
🔧 Core Utilities
String Utilities (StringUtility)
Comprehensive string manipulation and processing tools:
// URL and SEO-friendly string generation
string urlKey = StringUtility.GenerateUrlKey("My Blog Post Title!"); // "my-blog-post-title"
// HTML and symbol stripping
string cleanText = StringUtility.StripHTML("<p>Hello <b>World</b></p>"); // "Hello World"
string alphanumeric = StringUtility.StripSymbols("Hello @World! 123"); // "Hello World 123"
// Date-based unique identifiers
string dateCode = StringUtility.GetDateCode(); // File time-based code
string updateId = StringUtility.AddUpDate(); // Timestamp-based ID
// Tag generation
string tags = StringUtility.GenerateTags("tag1", "tag2", "tag3"); // "tag1,tag2,tag3"
Image Processing (ImageUtility)
Advanced image manipulation capabilities:
// Image scaling with aspect ratio preservation
Image scaledImage = ImageUtility.ScaleImage(sourceImage, 800, 600, ImageSizePreference.Width);
// Image cropping and resizing
Image croppedImage = ImageUtility.CropImage(sourceBitmap, 300, 300);
Bitmap resizedImage = ImageUtility.ResizeImage(sourceImage, 400, 300);
// Format conversion
byte[] imageBytes = ImageUtility.ConvertBitmapToBytes(bitmap, ImageFormat.Jpeg);
string base64Image = ImageUtility.ConvertImageToBase64(image, ImageFormat.Png);
// High-quality JPEG saving
ImageUtility.SaveJpegToFile("output.jpg", image, quality: 85);
Cryptography & Security
Encryption (Encryption)
string key = "MySecretEncryptionKeyThatIsLongEnough123"; // 32+ chars required
string encrypted = Encryption.Encrypt("sensitive data", key);
string decrypted = Encryption.Decrypt(encrypted, key);
Cryptography (Crypto)
// Hashing algorithms
string salt = Crypto.CreateSalt(128);
string sha256Hash = Crypto.EncodeSHA256("password", salt);
string sha512Hash = Crypto.EncodeSHA512("password", salt);
string sha1Hash = Crypto.EncodeSHA1("password");
// Base64 encoding/decoding
string encoded = Crypto.EncodeBase64("text to encode");
string decoded = Crypto.DecodeBase64(encoded);
OTP (One-Time Password) Utilities (OtpUtility)
// Generate OTP with custom expiry
var otpResult = OtpUtility.GenerateCode("user@example.com", 12345, TimeSpan.FromMinutes(5));
Console.WriteLine($"Code: {otpResult.Code}, Expires: {otpResult.ExpiryTime}");
// Validate OTP
bool isValid = OtpUtility.ValidateCode("user@example.com", 12345, "123456", otpResult.ExpiryTime);
Number Base Conversion (BaseConverter)
Convert numbers between different bases and formats:
// Convert from any base to decimal
long decimal = BaseConverter.ConvertToDecimal("1010", 2); // Binary to decimal: 10
long hexDecimal = BaseConverter.ConvertToDecimal("FF", 16); // Hex to decimal: 255
// Convert decimal to any base
string binary = BaseConverter.ConvertFromDecimal(10, 2); // "1010"
string hex = BaseConverter.ConvertFromDecimal(255, 16); // "FF"
// Convert to alphabetic representation
string alpha = BaseConverter.ConvertToAlpha(26); // "BA"
EditorJS Integration (EditorJS)
Parse and convert EditorJS content to HTML:
// Parse EditorJS JSON to HTML
string html = EditorJS.Parse(editorJsJsonString);
// Supports: headers, paragraphs, lists, images, embeds (YouTube, Vimeo)
🔌 Extension Methods
String Extensions (StringExtensions)
Powerful string manipulation extensions:
// Value toggling
string toggled = "active".Toggle("inactive"); // "inactive"
// Case-insensitive operations
bool contains = "Hello World".Search("WORLD"); // true
bool equals = "Hello".EqualsNoCase("HELLO"); // true
// Number and symbol extraction
string numbers = "abc123def456".ExtractNumbers(); // "123456"
string clean = "Hello;World*".StripSymbols(); // "HelloWorld" (removes specific symbols)
// Type conversions
int number = "abc123".ToInt32(); // 123
decimal price = "Price: $29.99".ToDecimal(); // 29.99
// CSV processing
List<string> items = "apple,banana,cherry".ToListFromCsv();
HashSet<string> uniqueItems = "apple,banana,apple".ToHashSetFromCsv();
DateTime Extensions (DateTimeExtensions)
Enhanced DateTime formatting:
DateTime now = DateTime.Now;
string dateStr = now.ToDateString(); // "15/Aug/2025"
string dateTimeStr = now.ToDateTimeString(); // "15/Aug/2025 14:30:15"
☁️ Azure Integration
Azure App Configuration Integration (AppConfigurationExtensions)
NEW in v3.2.0 - Comprehensive Azure App Configuration support with advanced features:
// Define settings class with regular config and feature flags
public class AppSettings
{
public string DatabaseConnectionString { get; set; }
[AppConfigurationKey("MyApp:ApiKey")]
public string ApiKey { get; set; }
public int MaxRetries { get; set; }
// Feature flags (bool/bool? only)
[FeatureFlag("enable-new-ui")]
public bool NewUiEnabled { get; set; }
[FeatureFlag("beta-features")]
public bool? BetaFeaturesEnabled { get; set; }
}
// Web Applications - Using Managed Identity (recommended for Azure)
var builder = WebApplication.CreateBuilder(args);
builder.AddAppConfigurationForWebApplication<AppSettings>(
appConfigEndpoint: new Uri("https://myapp.azconfig.io"),
out AppSettings settings,
label: "Production", // Environment-specific config
keyFilter: "MyApp:*", // Filter keys by prefix
credential: new DefaultAzureCredential()
);
// Web Applications - Using Connection String (flexible)
builder.AddAppConfigurationForWebApplication<AppSettings>(
connectionString: Environment.GetEnvironmentVariable("AppConfigConnectionString"),
out AppSettings settings,
label: "Staging"
);
// Azure Functions - Direct client access with environment fallback
hostBuilder.AddAppConfigurationForAzureFunctions<AppSettings>(
appConfigEndpoint: new Uri("https://myapp.azconfig.io"),
out AppSettings functionSettings,
skipDevelopment: true // Uses environment variables in dev
);
// Optional: Configuration refresh with sentinel keys
var refreshOptions = new AppConfigurationRefreshOptions
{
EnableRefresh = true,
RefreshInterval = TimeSpan.FromMinutes(5), // Minimum 30s recommended
SentinelKeys = new[] { "AppSettings:Version" }, // Trigger refresh
OnRefreshError = ex => logger.LogWarning(ex, "Config refresh failed")
};
builder.AddAppConfigurationForWebApplication<AppSettings>(
appConfigEndpoint: new Uri("https://myapp.azconfig.io"),
out AppSettings settings,
refreshOptions: refreshOptions
);
Key Features:
- ✅ Label-based environment configs (Production, Staging, Development)
- ✅ Key filtering with wildcards (
MyApp:*,Database:*) - ✅ Attribute-based feature flags with bool validation
- ✅ Optional auto-refresh with sentinel keys
- ✅ Managed Identity or connection string authentication
- ✅ Development fallback to environment variables
- ✅ Automatic type conversion and error handling
Key Vault Integration (KeyVaultExtensions)
Robust Azure Key Vault integration for secrets management:
// Define your settings class
public class AppSettings
{
public string DatabaseConnectionString { get; set; }
[KeyVaultKey("api-key")]
public string ApiKey { get; set; }
}
// For ASP.NET Web Applications
var builder = WebApplication.CreateBuilder(args);
builder.AddKeyVaultForWebApplication<AppSettings>(
keyVaultUri: "https://your-keyvault.vault.azure.net/",
out AppSettings settings
);
// For Azure Functions
hostBuilder.AddKeyVaultForAzureFunctions<AppSettings>(
keyVaultUri: "https://your-keyvault.vault.azure.net/",
out AppSettings functionSettings
);
Azure Storage (AzureStorageManager)
Azure Blob Storage operations:
string connectionString = "DefaultEndpointsProtocol=https;AccountName=...";
// Upload operations
AzureStorageManager.UploadToAzure(connectionString, "container", stream, "application/pdf", "file.pdf", "folder");
// Download operations
AzureStorageManager.DownloadFromAzure(connectionString, "container", fileInfo, "folder");
// Check folder existence
bool exists = AzureStorageManager.AzureFolderExists(connectionString, "container", "folder");
Service Collection Extensions (ServicesExtensions)
Automatic service registration by interface:
// Register all services implementing IService
services.AddScopedServicesByInterface<IService>();
services.AddSingletonServicesByInterface<IRepository>();
services.AddTransientServicesByInterface<IValidator>();
🌐 HTTP Client
API Client (ApiClient)
Comprehensive HTTP client with built-in error handling and serialization:
// Initialize
var apiClient = new ApiClient(httpClient);
// GET with various options
var user = await apiClient.GetAsync<User>("https://api.example.com/users/1");
var userWithAuth = await apiClient.GetAsync<User>("https://api.example.com/users/1", bearerToken);
// POST operations
var response = await apiClient.PostAsync("https://api.example.com/users", newUser);
var createdUser = await apiClient.PostAsync<User, User>("https://api.example.com/users", newUser);
// reCAPTCHA validation
var captchaResult = await apiClient.ValidateGoogleCaptcharAsync(secretKey, response, remoteIp);
🛡️ Middleware
Request Validation Middleware (RequestValidationMiddleware)
ASP.NET Core middleware for API key validation:
// Setup
services.AddRequestValidation("your_secret_api_key", skipForDevelopment: true);
app.UseRequestValidation();
// Client usage - include key in headers
client.DefaultRequestHeaders.Add("key", "your_secret_api_key");
📊 Data Models
Smart Enums (SmartEnum<TEnum>)
Type-safe enumeration base class with value and name support:
// Define your SmartEnum
public class OrderStatus : SmartEnum<OrderStatus>
{
public static readonly OrderStatus Pending = new OrderStatus("Pending", 1);
public static readonly OrderStatus Processing = new OrderStatus("Processing", 2);
public static readonly OrderStatus Shipped = new OrderStatus("Shipped", 3);
public static readonly OrderStatus Delivered = new OrderStatus("Delivered", 4);
private OrderStatus(string name, int value) : base(name, value) { }
}
// Usage examples
var status = OrderStatus.Parse(2); // Get by value: Processing
var statusByName = OrderStatus.Parse("Shipped"); // Get by name: Shipped
// List all values
foreach (var status in OrderStatus.List())
{
Console.WriteLine($"{status.Name}: {status.Value}");
}
// Type-safe comparisons
OrderStatus current = OrderStatus.Processing;
if (current.Equals(OrderStatus.Processing))
{
Console.WriteLine("Order is being processed");
}
Features:
- Type-safe enumeration pattern
- Parse by value or name (case-insensitive)
- List all enum values
- Strongly-typed with compile-time safety
- Thread-safe initialization
Fluent Dictionary (FluentDictionary<TKey, TValue>)
Chainable dictionary operations with fluent API:
using Clear;
// Create and populate in one fluent chain
var config = new FluentDictionary<string, string>()
.Add("host", "localhost")
.Add("port", "5432")
.Add("database", "mydb")
.Add("username", "admin");
// Use the static factory method
var settings = FluentDictionary<string, int>.Create("timeout", 30)
.Add("retries", 3)
.Add("maxConnections", 100);
// Chain Add and Remove operations
var userPrefs = new FluentDictionary<string, bool>()
.Add("darkMode", true)
.Add("notifications", true)
.Add("autoSave", false)
.Remove("autoSave")
.Add("autoSave", true);
// All Dictionary<TKey, TValue> methods available
bool hasKey = config.ContainsKey("host");
bool hasValue = config.TryGetValue("port", out string portValue);
Features:
Fluent, chainable API for dictionary operations
Returns
thisfor method chaining onAdd()andRemove()Static
Create()factory method for initializationInherits all standard
Dictionary<TKey, TValue>functionalityType-safe with full generic support
Simplifies builder pattern and configuration setup
ValidationCodeResult: OTP generation results with code and expiryCaptcherResponse: Google reCAPTCHA validation responseEditorJS Models: Complete data structures for EditorJS content parsing
📦 Installation & Setup
Package Installation
# Via .NET CLI
dotnet add package ClearTools
# Via PackageReference
<PackageReference Include="ClearTools" Version="3.1.0" />
Dependencies
ClearTools targets .NET Standard 2.1 and includes:
- Azure.Storage.Blobs (12.25.0)
- Azure.Security.KeyVault.Secrets (4.8.0)
- Newtonsoft.Json (13.0.3)
- System.Drawing.Common (9.0.8)
- Microsoft.AspNetCore.Http.Abstractions (2.3.0)
📖 Examples
Complete Image Processing Pipeline
public class ImageProcessor
{
public async Task<string> ProcessAndUploadImage(IFormFile file)
{
using var stream = file.OpenReadStream();
var image = Image.FromStream(stream);
// Process image
var scaledImage = ImageUtility.ScaleImage(image, 800, 600);
var imageBytes = ImageUtility.ConvertBitmapToBytes((Bitmap)scaledImage, ImageFormat.Jpeg);
// Generate unique filename
var fileName = StringUtility.GenerateFileName(file.FileName, "jpg");
// Upload to Azure
using var uploadStream = new MemoryStream(imageBytes);
AzureStorageManager.UploadToAzure(connectionString, "images", uploadStream, "image/jpeg", fileName, "uploads");
return fileName;
}
}
OTP Service Implementation
public class OtpService
{
private readonly int _secretKey = 123456;
public ValidationCodeResult GenerateOtp(string email)
{
return OtpUtility.GenerateCode(email, _secretKey, TimeSpan.FromMinutes(5));
}
public bool ValidateOtp(string email, string code, DateTime expiry)
{
return OtpUtility.ValidateCode(email, _secretKey, code, expiry);
}
}
📚 Documentation
For comprehensive documentation covering all methods and use cases, see:
- Complete Usage Guide - Detailed documentation with examples for every class and method
- API Reference - Complete API documentation
- Changelog - Version history and changes
🏷️ Features Summary
✅ String Utilities: URL generation, HTML stripping, text processing
✅ Image Processing: Scaling, cropping, format conversion, quality optimization
✅ Cryptography: Hashing, encryption, salt generation, secure tokens
✅ OTP Management: Generation, validation, expiry handling
✅ Azure Integration: Key Vault, Blob Storage, managed identity support
✅ HTTP Client: RESTful API client with authentication and serialization
✅ Extensions: String, DateTime, Byte array, and service collection extensions
✅ Middleware: Request validation, API key authentication
✅ EditorJS: Content parsing and HTML conversion
✅ Base Conversion: Number base conversion utilities
✅ File Management: File I/O operations and utilities
🤝 Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
📞 Support
- Issues: GitHub Issues
- NuGet Package: ClearTools on NuGet
- Documentation: Complete Usage Guide
ClearTools - Making .NET development clearer, one utility at a time. 🚀
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Azure.Data.AppConfiguration (>= 1.4.1)
- Azure.Extensions.AspNetCore.Configuration.Secrets (>= 1.4.0)
- Azure.Identity (>= 1.15.0)
- Azure.Security.KeyVault.Secrets (>= 4.8.0)
- Azure.Storage.Blobs (>= 12.25.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Configuration.AzureAppConfiguration (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Hosting (>= 9.0.8)
- Newtonsoft.Json (>= 13.0.3)
- System.Drawing.Common (>= 9.0.8)
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 |
|---|---|---|
| 3.2.0 | 82 | 12/22/2025 |
| 3.1.1 | 254 | 11/14/2025 |
| 3.1.0 | 271 | 11/13/2025 |
| 3.0.9 | 474 | 8/21/2025 |
| 3.0.7 | 544 | 7/3/2025 |
| 3.0.7-preview1 | 186 | 7/3/2025 |
| 3.0.6 | 229 | 6/30/2025 |
| 3.0.5 | 282 | 6/26/2025 |
| 3.0.5-preview1 | 332 | 6/10/2025 |
| 3.0.4 | 436 | 3/28/2025 |
| 3.0.2 | 231 | 2/20/2025 |
| 3.0.1 | 203 | 2/13/2025 |
| 3.0.0 | 237 | 12/19/2024 |
| 2.1.23-preview5 | 162 | 12/10/2024 |
| 2.1.23-preview3 | 137 | 10/23/2024 |
| 2.1.23-preview2 | 160 | 9/18/2024 |
| 2.1.23-preview1 | 145 | 7/5/2024 |
| 2.1.22 | 286 | 2/2/2024 |
| 2.1.22-preview1 | 136 | 7/5/2024 |
| 2.1.21 | 203 | 2/1/2024 |
| 2.1.20 | 649 | 7/25/2022 |
| 2.1.19 | 622 | 7/17/2022 |
| 2.1.18 | 663 | 7/17/2022 |
| 2.1.17 | 607 | 8/24/2021 |
| 2.1.16 | 608 | 7/3/2021 |
| 2.1.15 | 624 | 7/2/2021 |
| 2.1.14 | 601 | 6/12/2021 |
| 2.1.13 | 592 | 4/6/2021 |
| 2.1.12 | 758 | 6/19/2020 |
| 2.1.11 | 762 | 6/18/2020 |
| 2.1.10 | 714 | 6/18/2020 |
| 2.1.9 | 720 | 6/18/2020 |
| 2.1.8 | 786 | 11/15/2019 |
| 2.1.7 | 785 | 9/11/2019 |
| 2.1.6 | 836 | 7/24/2019 |
| 2.1.5 | 797 | 7/17/2019 |
| 2.1.4 | 818 | 7/17/2019 |
| 2.1.3 | 821 | 7/17/2019 |
| 2.1.2 | 809 | 7/16/2019 |
| 2.1.1 | 995 | 1/11/2019 |
| 1.0.0 | 966 | 12/29/2018 |