Kaz.Operations
2.0.0
Prefix Reserved
dotnet add package Kaz.Operations --version 2.0.0
NuGet\Install-Package Kaz.Operations -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="Kaz.Operations" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kaz.Operations" Version="2.0.0" />
<PackageReference Include="Kaz.Operations" />
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 Kaz.Operations --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Kaz.Operations, 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 Kaz.Operations@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=Kaz.Operations&version=2.0.0
#tool nuget:?package=Kaz.Operations&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Kaz.Operations
Provides string manipulation, numeric conversion, collection algorithms, cryptographic hashing, date/time validation, file I/O, system environment access, and certificate utilities for .NET Framework 4.7.2.
Features
Kaz.Operations.TextString editing and manipulation:
Reverse
string example = "abc"; string reversed = example.Reverse(); // cbaRemoveWhiteSpaces
string example = "a b c"; string noWhiteSpaces = example.RemoveWhiteSpaces(); // abcExtractAllNumbers
string example = "a1b2c"; var digits = input.ExtractAllNumbers(NumberExtractionOptions.Digits); // 1, 2 (List<string>)ExtractPattern
Regex regex = new Regex(@"[A-Z]"); string example = "Hello User!".ExtractPattern(regex); // HUIf Regex is null, an exception will be thrown:
string example = "Hello User!".ExtractPattern(null); // Throws ArgumentNullException
Checking strings for format compliance:
IsNumeric
string example = "123"; bool isNumeric = example.IsNumeric(); // trueIsEmail
string example = "example@gmail.com"; bool isEmail = example.IsEmail(); // true string example1 = "@hi.gmail.com"; bool isEmail1 = example1.IsEmail(); // falseIsPhoneNumber
string example = "+442079460000"; // only supports E.164 format bool isPhoneNumber = example.IsPhoneNumber(); // true string example1 = "+012345"; bool isPhoneNumber1 = example1.IsPhoneNumber(); // falseIsAlpha
string example = "Hello World"; bool isAlpha = example.IsAlpha(); // true string example1 = "Hello123"; bool isAlpha1 = example1.IsAlpha(); // falseIsBoolean
bool result = "true".IsBoolean(); // true bool result1 = "1".IsBoolean(); // true bool result2 = "yes".IsBoolean(); // falseIsUrl
bool result = "https://example.com".IsUrl(); // true // With specific scheme bool result1 = "http://example.com".IsUrl(UrlScheme.Https); // false bool result2 = "https://example.com".IsUrl(UrlScheme.Https); // trueIsIpAddress
bool result = "192.168.1.1".IsIpAddress(); // true // With specific version bool result1 = "192.168.1.1".IsIpAddress(IpVersion.IPv4); // true bool result2 = "::1".IsIpAddress(IpVersion.IPv6); // trueMatchesPattern (+1 overload)
bool result = "Hello123".MatchesPattern(@"^[A-Za-z0-9]+$"); // true // With RegexOptions bool result1 = "HELLO".MatchesPattern(@"^hello$", RegexOptions.IgnoreCase); // true
Kaz.Operations.NumericsSafe conversion of string values into numeric types:
ToNumericOrDefault<T>
// Supported types: int, long, float, double, decimal, short, byte. string example = "123"; int number = example.ToNumericOrDefault<int>(0); // 123 string invalidExample = "invalid"; int fallback = invalidExample.ToNumericOrDefault<int>(0); // 0 (Specified default value) string example1 = "19.99"; double price = example1.ToNumericOrDefault<double>(0.0); // 19.99
Math operations:
Clamp<T>
int number = 10; int result = number.Clamp(0, 5); // 5CalculatePercentage<T>
double number = 500; // FractionOfTotal (Calculates 10% of 500) double result = number.CalculatePercentage(10, PercentageCalculationMethod.FractionOfTotal); // 50 decimal number1 = 1000m; // RatioOfTotal (Calculates percentage ratio) decimal total = number1.CalculatePercentage(20, PercentageCalculationMethod.RatioOfTotal); // 200Lerp (+2 overloads)
// Also supports overloads for float and decimal double example = 15; Console.WriteLine(example.Lerp(16, 0.5)); // 15.5Factorial (+1 overload)
// Also supports long overload int number = 5; int result = number.Factorial(); // 120IsPrime (+1 overload)
// Also supports long overload int number = 7; bool result = number.IsPrime(); // true int number1 = 10; bool result1 = number1.IsPrime(); // false
Kaz.Operations.CollectionsSorting IList collections:
MergeSort
var items = new List<int> { 5, 3, 8, 1 }; items.MergeSort(); // [1, 3, 5, 8]CountingSort
var users = new List<User> { new User { Id = 103, Name = "Alice" }, new User { Id = 101, Name = "Bob" } }; users.CountingSort(u => u.Id); // Sorted by Id propertyBubbleSort
int[] list = {3, 2, 1}; list.BubbleSort(); // [1, 2, 3]SelectionSort
int[] list = {3, 2, 1}; list.SelectionSort(); // [1, 2, 3]
Searching through IList collections:
LinearSearch
var list = new List<int> { 1, 2, 3 }; int index = list.LinearSearch(2); // 1BinarySearch
// List must be sorted var list = new List<int> { 1, 2, 3, 4, 5 }; int index = list.BinarySearch(3); // 2InterpolationSearch
// List must be sorted, works only with int var list = new List<int> { 10, 20, 30, 40, 50 }; int index = list.InterpolationSearch(30); // 2
- Note:
BubbleSortandSelectionSortare marked as deprecated and are not recommended for use (for educational purposes only).
Kaz.Operations.TimeChecking date and time conditions:
IsWeekend
DateTime date = new DateTime(2025, 1, 4); // Saturday bool result = date.IsWeekend(); // trueIsWeekday
DateTime date = new DateTime(2025, 1, 6); // Monday bool result = date.IsWeekday(); // trueIsPastDate
DateTime date = DateTime.UtcNow.AddDays(-1); bool result = date.IsPastDate(); // trueIsPresentDate
DateTime date = DateTime.UtcNow; bool result = date.IsPresentDate(); // trueIsFutureDate
DateTime date = DateTime.UtcNow.AddDays(1); bool result = date.IsFutureDate(); // true
Validating date and time values:
IsValidTime
bool result = Validation.IsValidTime(seconds: 30, minutes: 45, hours: 12); // true bool result1 = Validation.IsValidTime(seconds: 61, minutes: 0, hours: 0); // falseIsValidDate (+2 overloads)
bool result = "2025-01-01".IsValidDate(); // true bool result1 = "not-a-date".IsValidDate(); // false // With format bool result2 = "01/01/2025".IsValidDate("MM/dd/yyyy"); // true // With format and culture bool result3 = "01.01.2025".IsValidDate("dd.MM.yyyy", new CultureInfo("de-DE")); // trueIsValidMonth
bool result = 6.IsValidMonth(); // true bool result1 = 13.IsValidMonth(); // falseIsInRange
DateTime date = new DateTime(2025, 6, 15); DateTime from = new DateTime(2025, 1, 1); DateTime to = new DateTime(2025, 12, 31); bool result = date.IsInRange(from, to); // trueIf bound1 is greater than bound2, an exception will be thrown:
date.IsInRange(to, from); // Throws ArgumentException
Kaz.Operations.IOFile CRUD operations:
AppendLine
bool success = CRUD.AppendLine("logs/app.log", "Application started."); // trueCopyIfNewer
bool copied = CRUD.CopyIfNewer("source/config.json", "backup/config.json"); // true if source is newerReadAllLines (+1 overload)
List<string> lines = CRUD.ReadAllLines("data/file.txt"); // Skip empty lines List<string> filtered = CRUD.ReadAllLines("data/file.txt", skipEmpty: true);GetFilesByExtension
List<string> files = CRUD.GetFilesByExtension("logs/", ".log"); // or List<string> files1 = CRUD.GetFilesByExtension("logs/", "log"); // both formats supportedTryDelete
bool deleted = CRUD.TryDelete("temp/file.tmp"); // true if file existed and was deleted
File and directory validation:
EnsureExists
Validation.EnsureExists("logs/archive"); // Creates directory if it doesn't existIsFileLocked
bool locked = Validation.IsFileLocked("data/file.db"); // true if file is in use
Note:
CRUD.Encodingdefaults to UTF-8 and can be changed:CRUD.Encoding = Encoding.Unicode;
Kaz.Operations.Security.CryptographyHashing algorithms:
Sha256.Hash (+1 overload)
string hash = Sha256.Hash("hello world"); // With custom encoding string hash1 = Sha256.Hash("hello world", Encoding.Unicode);Sha256.Compare (+2 overloads)
bool match = Sha256.Compare("hello world", hash); // Compare against byte array bool match1 = Sha256.Compare("hello world", hashBytes);- Same API available for
Sha512andMd5.
HMAC algorithms:
HmacSha256.Hash (+1 overload)
byte[] key = Encoding.UTF8.GetBytes("secret-key"); string hash = HmacSha256.Hash("message", key);HmacSha256.Compare (+3 overloads)
bool match = HmacSha256.Compare("message", hash, key);- Same API available for
HmacSha1andHmacSha512.
Password hashing:
Pbkdf2.HMACSHA256
byte[] salt = Pbkdf2.GenerateSalt(); string hash = Pbkdf2.HMACSHA256("my-password", salt, iterationCount: 10000);Pbkdf2.Compare
bool match = Pbkdf2.Compare("my-password", salt, 10000, HashAlgorithmName.SHA256, hash);Pbkdf2.GenerateSalt (+1 overload)
byte[] salt = Pbkdf2.GenerateSalt(); // 32-byte cryptographically secure salt // With offset and count byte[] salt1 = Pbkdf2.GenerateSalt(offset: 0, count: 16);Note:
Pbkdf2.HMACSHA1is marked as deprecated and is not recommended for security-critical operations.
Kaz.Operations.SystemSystem and runtime information:
SystemInfo.IsAdministrator
bool isAdmin = SystemInfo.IsAdministrator; // true if elevatedSystemInfo.WorkingSetMb
double mb = SystemInfo.WorkingSetMb; // 134.5SystemInfo.IsWindowsVersionAtLeast (+1 overload)
bool result = SystemInfo.IsWindowsVersionAtLeast(10); // true on Windows 10+ // With minor version bool result1 = SystemInfo.IsWindowsVersionAtLeast(10, 0); // trueSystemInfo.GetUptime
TimeSpan uptime = SystemInfo.GetUptime(); // 2.05:13:44- Other properties:
MachineName,UserName,UserDomainName,ProcessorCount,Is64BitOperatingSystem,Is64BitProcess,OSVersion,DotNetVersion,SystemDirectory,CommandLine,HasShutdownStarted,NewLine,PlatformID,TickCount,CurrentManagedThreadId,WorkingSet.
Environment variables:
EnvironmentVariables.GetVariable (+1 overload)
string value = EnvironmentVariables.GetVariable("PATH", "default"); // With target scope string value1 = EnvironmentVariables.GetVariable("PATH", "default", EnvironmentVariableTarget.Machine);EnvironmentVariables.GetVariables
Dictionary<string, string> all = EnvironmentVariables.GetVariables();EnvironmentVariables.SetVariable (+1 overload)
EnvironmentVariables.SetVariable("MY_VAR", "hello");EnvironmentVariables.DeleteVariable (+1 overload)
EnvironmentVariables.DeleteVariable("MY_VAR");EnvironmentVariables.Exists
bool exists = EnvironmentVariables.Exists("PATH"); // true
System directories:
SystemDirectories.GetDriveFreeSpace
Dictionary<string, long> space = SystemDirectories.GetDriveFreeSpace(); // { "C:\", 53687091200 }- Other properties:
CurrentDirectory,Desktop,Documents,LocalAppData,Temporary.
Kaz.Operations.Security.CertificatesLoading certificates:
LoadCertificate
// Supported formats: .cer, .crt X509Certificate2 cert = X509CertificateInfo.LoadCertificate("mycert.cer");LoadCertificate (with password)
// Supported formats: .pfx, .p12 X509Certificate2 cert = X509CertificateInfo.LoadCertificate("mycert.pfx", "password");If the file extension is invalid, an exception will be thrown:
X509CertificateInfo.LoadCertificate("mycert.xyz"); // Throws ArgumentException
Certificate validation:
IsExpired
bool expired = cert.IsExpired(); // true if past expiration dateIsTrusted
bool trusted = cert.IsTrusted(); // true if certificate chain is validGetExpirationDate
DateTime expiresOn = cert.GetExpirationDate(); // 01/01/2026 00:00:00
Installation
- .NET CLI:
dotnet add package Kaz.Operations
- NuGet Package Manager:
Install-Package Kaz.Operations
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.7.2
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.