UNLEIN.Utilities
2.2.0
dotnet add package UNLEIN.Utilities --version 2.2.0
NuGet\Install-Package UNLEIN.Utilities -Version 2.2.0
<PackageReference Include="UNLEIN.Utilities" Version="2.2.0" />
<PackageVersion Include="UNLEIN.Utilities" Version="2.2.0" />
<PackageReference Include="UNLEIN.Utilities" />
paket add UNLEIN.Utilities --version 2.2.0
#r "nuget: UNLEIN.Utilities, 2.2.0"
#addin nuget:?package=UNLEIN.Utilities&version=2.2.0
#tool nuget:?package=UNLEIN.Utilities&version=2.2.0
UNLEIN® Utilities - C# Package
Overview
The UNLEIN® Utilities package is a comprehensive collection of ready-to-use methods designed to improve your C# applications. It simplifies tasks like generating hash values (both one-way and two-way), managing logging, handling file uploads, making API calls, and performing database operations. Whether you're building a simple app or a complex enterprise system, this package offers optimized, easy-to-use solutions.
Features
- Hash Generation:
- One-way hash values.
- Two-way hash values (with key for encryption/decryption).
- Hash generation for email subscriptions and unsubscribe tokens.
- File Handling:
- Get file details before upload.
- Generate Base64 string data from file before upload.
- Easy file upload with real-time renaming feature.
- Upload base64 string files.
- String Manipulation:
- SafeReplace method for precise find and replace operations.
- Shuffle characters in a string.
- Between String extension for extracting or removing substrings.
- Database Operations:
- Fast database connections for quick data retrieval.
- Query and query list methods for dynamic data binding.
- Bulk insert and insert queries.
- Support for complex data types and stored procedures.
- Logging:
- Simple, lightweight logging functionality.
- Auto logging for API calls.
- Supports
.NET
platforms above version 6.0. - Manage log files with "Rolling Interval" functionality.
- API Calls:
- Prebuilt methods for making GET, POST, PUT, PATCH, and DELETE requests.
- Automatic API request logging.
- Cookie Manager:
- Get, save, update, and delete cookies programmatically.
- Mathematical Operations:
- Advanced statistical functions (Standard Deviation, Moving Averages)
- Number theory operations (GCD, LCM, Prime checking)
- Combinatorics calculations (Combinations, Binomial Coefficients)
- Financial calculations (EMA, WMA)
- Mathematical series (Fibonacci)
- Root calculations and interpolation
- DateTime Extensions:
- Business day calculations
- Week and month boundary operations
- Human-readable time ago strings
- Date range operations
- Data Validation:
- Phone number validation
- Credit card validation
- URL and IP address validation
- Password strength checking
- Input type validation (letters, numbers)
- Collection Operations:
- Advanced collection chunking
- Random element selection
- Uniqueness checking
- Custom shuffling
- Frequency analysis
- Slicing operations
Official team
Program is Developed and Maintained By UNLEIN® Private Limited
Usage
Developer Utilities Usage
using UNLEIN.Utilities;
// URL Slug Generation
"Hello World! This is a test".ToSlug(); // "hello-world-this-is-a-test"
// Secure Random String
var randomString = DeveloperUtilities.GenerateRandomString(10); // e.g., "aX9#mK2$pL"
// Smart Text Truncation
"This is a very long text".TruncateWithEllipsis(10); // "This is..."
// Extract Numbers
"Product123ABC456".ExtractNumbers(); // "123456"
// File Size Formatting
(1234567L).FormatFileSize(); // "1.18 MB"
// Case Conversion
"thisIsATest".ToSentenceCase(); // "This is a test"
// Duration Formatting
TimeSpan.FromMinutes(45).ToReadableDuration(); // "45 minutes"
// Safe Enum Parsing
"DRAFT".ParseEnum(Status.Pending); // Returns Status.DRAFT or Status.Pending if invalid
// HTML Stripping
"<p>Hello <b>World</b></p>".StripHtml(); // "Hello World"
// String Masking
"1234567890".Mask(4); // "******7890"
// JSON Validation
"{\"name\":\"test\"}".IsValidJson(); // true
// Get Initials
"John Doe".GetInitials(); // "JD"
Mathematical Operations
using UNLEIN.Utilities;
// Statistical Analysis
var numbers = new[] { 1.0, 2.0, 3.0, 4.0, 5.0 };
double stdDev = numbers.StandardDeviation();
var movingAvgs = numbers.MovingAverage(3).ToList();
var ema = numbers.ExponentialMovingAverage(3).ToList();
// Number Theory
bool isPrime = 17L.IsPrime(); // true
long gcd = 48L.GCD(18L); // 6
long lcm = 12L.LCM(18L); // 36
// Advanced Calculations
double cubeRoot = 27.0.NthRoot(3); // 3.0
double interpolated = 0.0.Lerp(100.0, 0.5); // 50.0
// Combinatorics
long combinations = 5.Combinations(2); // 10
var fibSequence = 10.Fibonacci().ToList();
DateTime Operations
using UNLEIN.Utilities;
var date = DateTime.Now;
var weekStart = date.StartOfWeek();
var monthEnd = date.EndOfMonth();
var timeAgo = date.AddDays(-5).ToTimeAgo(); // "5 days ago"
var nextWorkday = date.NextBusinessDay();
Data Validation
using UNLEIN.Utilities;
"123-456-7890".IsValidPhoneNumber(); // true
"4532015112830366".IsValidCreditCard(); // true
"https://example.com".IsValidUrl(); // true
"192.168.1.1".IsValidIPv4(); // true
"Password123!".IsStrongPassword(); // true
Collection Operations
using UNLEIN.Utilities;
var numbers = Enumerable.Range(1, 10);
// Chunk large collections
var chunks = numbers.Chunk(3); // [[1,2,3], [4,5,6], [7,8,9], [10]]
// Get random element
var randomNumber = numbers.Random();
// Check uniqueness
var hasUnique = numbers.AllUnique(); // true
// Shuffle collection
var shuffled = numbers.Shuffle();
// Get slice of collection
var slice = numbers.Slice(2, 5); // [3,4,5]
// Group by frequency
var chars = "hello world".ToCharArray();
var frequency = chars.GroupByFrequency(c => c);
Logging
To start using the logging functionality, include the UNLEIN.Utilities.Log
namespace and configure your logger:
using UNLEIN.Utilities.Log;
var logger = new LoggingConfig()
.WriteFile("logs/log.txt", RollingInterval.Hour)
.Start();
Log.Info("Hey");
//Api Callings
var get = await Api.GetAsync("todos/1");
var post = await Api.PostAsync("posts", data);
//You can also use PUT, PATCH, and DELETE requests in the same way.
//To enable API logging, configure the following
//Auto Logging for API
Api.ApiLog.IsApiLog = true;
Api.ApiLog.IncBaseUrl = true;
Api.ApiLog.IncRequest = true;
Api.ApiLog.FilePath = "logs/apilog.txt";
Api._BaseUrl = "https://example.com/";
Enhanced API Client Usage
using UNLEIN.Utilities.Api;
// Configure the API client (do this once at startup)
ApiClient.Configure(config =>
{
config.BaseUrl = "https://api.example.com";
config.DefaultToken = "your-default-token";
config.TimeoutSeconds = 30;
config.EnableCache = true;
config.DefaultCacheSeconds = 300;
config.EnableLogging = true;
});
// GET requests with automatic deserialization
var response = await ApiClient.GetAsync<UserModel>("users/1");
if (response.IsSuccessful)
{
var user = response.Data;
Console.WriteLine($"User: {user.Name}");
}
// GET with query parameters
var searchResponse = await ApiClient.GetListAsync<UserModel>("users", new
{
page = 1,
pageSize = 10,
search = "john"
});
// POST with custom options
var createResponse = await ApiClient.PostAsync<UserModel>(
"users",
new { name = "John", email = "john@example.com" },
new RequestOptions
{
Token = "custom-token",
Headers = new Dictionary<string, string>
{
["Custom-Header"] = "Value"
}
}
);
// File upload
using var formData = new MultipartFormDataContent();
formData.Add(new StreamContent(File.OpenRead("file.pdf")), "file", "file.pdf");
var uploadResponse = await ApiClient.PostFormAsync<FileUploadResponse>(
"upload",
formData
);
// Download file
using var fileStream = await ApiClient.GetFileAsync("files/download/123");
await using var outputStream = File.Create("downloaded.pdf");
await fileStream.CopyToAsync(outputStream);
// PUT request
var updateResponse = await ApiClient.PutAsync<UserModel>(
"users/1",
new { name = "Updated Name" }
);
// DELETE request
var deleteResponse = await ApiClient.DeleteAsync<object>("users/1");
// Handling errors
try
{
var response = await ApiClient.GetAsync<UserModel>(
"users/999",
options: new RequestOptions { ThrowOnError = true }
);
}
catch (ApiException ex)
{
Console.WriteLine($"API error {ex.StatusCode}: {ex.Message}");
}
The enhanced API client provides:
- Fluent configuration
- Automatic response caching
- Retry policy for failed requests
- File upload/download support
- Query parameter building
- Custom headers and tokens
- Detailed error information
- Automatic logging
- Type-safe responses
Advanced Database Operations
using UNLEIN.Utilities.Database;
// Initialize connection
DbExtensions.Initialize("your_connection_string");
// Simple typed query
var users = await DbExtensions.QueryAsync<User>("SELECT * FROM Users WHERE Age > @Age",
new { Age = 18 });
// Dynamic query with flexible properties
var results = await DbExtensions.QueryDynamicAsync(
"SELECT FirstName, LastName, Email FROM Users");
foreach (dynamic user in results)
{
Console.WriteLine($"{user.FirstName} {user.LastName}");
}
// Stored procedure with output parameters
public class UserParams
{
public int UserId { get; set; }
[ParameterDirection(ParameterDirection.Output)]
public string Status { get; set; }
}
var (users, outputs) = await DbExtensions.ExecuteStoredProcAsync<User>(
"GetUserDetails",
new UserParams { UserId = 1 }
);
Console.WriteLine($"Status: {outputs["@Status"]}");
// Bulk insert
var newUsers = new List<User> { /* ... */ };
await DbExtensions.BulkInsertAsync("Users", newUsers);
// Multiple result sets
using (var results = await DbExtensions.QueryMultipleAsync(@"
SELECT * FROM Users;
SELECT * FROM Orders;"))
{
var users = results.Read<User>();
var orders = results.Read<Order>();
}
The new database extensions provide:
- Strong-typed query results
- Dynamic query results
- Stored procedure support with output parameters
- Efficient bulk insert operations
- Multiple result set handling
- Async/await support throughout
- Parameter mapping
- Automatic null handling
Change Logs
- [12.06.2025 2.2.0]:
- [NEW]: Enhanced API Client with built-in response caching
- [NEW]: Improved thread-safety in API operations
- [NEW]: Added retry policies for failed API requests
- [FIX]: Various stability improvements in API client
- [05.06.2025 2.1.0]:
- [NEW]: Advanced Mathematical Operations Added
- [NEW]: DateTime Extensions for Business Logic
- [NEW]: Data Validation Extensions
- [NEW]: Enhanced Collection Operations
- [28.11.2024 2.0.8/9]:
- [NEW]: Official Logo Added of unlein.utilites package
- [28.11.2024 2.0.7]:
- [NEW]: Api Callings Added, Now you don't need to write Api Calling code every time, just use most optimized, fast, very easy to use with auto logging feature of api callings, prebuilt methods from unlein.Utilities.
- [20.11.2024 2.0.6]:
- [NEW]: Added Logging functionality. It is easy to set up, has a clean API, and runs on all .NET platforms above 6.0. While it's useful even in the simplest applications, it's much lightweight and very simple to use, also manage log files with "Rolling Interval" functionality.
- [16.11.2024 2.0.5]:
- [NEW]: Optimized and Improvements
- [15.11.2024 2.0.4]:
- [NEW]: String Extension Added for Get/Remove Between values from string
- [15.11.2024 2.0.3]:
- [NEW]: Query and QueryList TWO methods added for select and bind dynamically data into model and list model
- [14.11.2024 2.0.2]:
- [NEW]: Optimized and Improvements
- [07.11.2024 2.0.1]:
- [NEW]: Bulk Insert and Insert Queries Added
- [23.10.2024 2.0.0]:
- [NEW]: Now Make Database Connections for Retrive fast data
- [15.09.2024 1.0.22]:
- [NEW]: Added Cookie Manager for Get/Save/Update/Delete Cookie From Code
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 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. |
-
net6.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
- Microsoft.Extensions.Caching.Memory (>= 9.0.5)
- Microsoft.Extensions.Http.Polly (>= 9.0.5)
- Newtonsoft.Json (>= 13.0.3)
- Polly (>= 8.5.2)
- System.Data.SqlClient (>= 4.9.0)
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
- Microsoft.Extensions.Caching.Memory (>= 9.0.5)
- Microsoft.Extensions.Http.Polly (>= 9.0.5)
- Newtonsoft.Json (>= 13.0.3)
- Polly (>= 8.5.2)
- System.Data.SqlClient (>= 4.9.0)
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 |
---|---|---|
2.2.0 | 270 | 6/12/2025 |
2.1.0 | 128 | 6/5/2025 |
2.0.9 | 138 | 11/29/2024 |
2.0.8 | 107 | 11/29/2024 |
2.0.7 | 113 | 11/29/2024 |
2.0.6 | 161 | 11/20/2024 |
2.0.5 | 109 | 11/16/2024 |
2.0.4 | 122 | 11/15/2024 |
2.0.3 | 112 | 11/15/2024 |
2.0.2 | 110 | 11/14/2024 |
2.0.1 | 152 | 11/7/2024 |
2.0.0 | 120 | 10/23/2024 |
1.0.22 | 144 | 9/15/2024 |
1.0.21 | 143 | 5/20/2024 |
1.0.20 | 211 | 12/11/2023 |
1.0.19 | 209 | 10/16/2023 |
1.0.18 | 182 | 10/14/2023 |
1.0.17 | 159 | 10/14/2023 |
1.0.16 | 140 | 10/14/2023 |
1.0.15 | 133 | 10/5/2023 |
1.0.14 | 206 | 8/6/2023 |
1.0.13 | 170 | 8/6/2023 |
1.0.12 | 179 | 7/20/2023 |
1.0.11 | 213 | 6/10/2023 |
1.0.10 | 195 | 6/10/2023 |
1.0.9 | 190 | 5/21/2023 |
1.0.8 | 175 | 5/14/2023 |
1.0.7 | 166 | 5/13/2023 |
1.0.6 | 185 | 5/8/2023 |
1.0.5 | 201 | 5/7/2023 |
1.0.4 | 186 | 5/7/2023 |
- [NEW]: Enhanced API Client with built-in response caching
- [NEW]: Improved thread-safety in API operations
- [NEW]: Added retry policies for failed API requests
- [FIX]: Various stability improvements in API client