Documentation

Utilities for common development tasks in .NET: console output helpers, flow control (conditions, retries, and waiters), hashing (Argon2id), file I/O helpers…

Utilities for common development tasks in .NET: console output helpers, flow control (conditions, retries, and waiters), hashing (Argon2id), file I/O helpers, HTTP client helpers, math utilities, random values and strings, regex helpers, text and email helpers, and small collections.

Installation

dotnet add package ArturRios.Util

The package targets net10.0 and depends on ArturRios.Output, which provides result envelopes.

Quickstart

  • Collections

    using ArturRios.Util.Collections;
    Console.WriteLine($"{AnsiColors.Green}Success!{AnsiColors.Reset}");
    var pool = Characters.Digits + Characters.UpperLetters;
    
  • Console

    using ArturRios.Util.Console;
    CustomConsole.WriteCharLine();          // 100 dashes
    CustomConsole.WriteCharLine('=', 40);   // 40 equals signs
    
  • FlowControl

    using ArturRios.Util.FlowControl;
    using ArturRios.Util.FlowControl.Waiter;
    
    Condition.Create
      .True(user is not null).FailsWith("User is required")
      .True(emailValid).FailsWith("Invalid email")
      .ThrowIfNotSatisfied();
    
    Retry.New.MaxAttempts(3).DelayMilliseconds(200).Execute(() => DoFragileWork());
    var result = Retry.New.MaxAttempts(5).Execute(() => Compute());
    
    var waiter = new JitteredWaiter(maxRetryCount: 5);
    while (waiter.CanRetry)
    {
        try { await TryOperationAsync(); break; }
        catch { await waiter.WaitAsync(); }
    }
    
  • Hashing

    using ArturRios.Util.Hashing;
    var hash = Hash.EncodeWithRandomSalt("secret", out var salt);
    var ok = Hash.TextMatches("secret", hash, salt);
    
  • Http

    using ArturRios.Util.Http;
    var gateway = new HttpGateway(httpClient);
    var output = await gateway.GetAsync<MyResponse>("/api/items");
    if ((int)output.StatusCode == HttpStatusCodes.Ok)
        Console.WriteLine(output.Body);
    
  • IO

    using ArturRios.Util.IO;
    var text  = FileReader.Read(path);
    var lines = FileReader.ReadLines(path);
    var dict  = FileReader.ReadAsDictionary(path, ',');
    var obj   = FileReader.ReadAndDeserialize<MyType>(jsonPath);
    // Async variants available on FileReaderAsync
    
  • Math

    using ArturRios.Util.Math;
    bool isPrime = PrimeUtils.IsPrimeNumber(7919); // true
    var generator = new PrimeGenerator<int>();
    Console.WriteLine(generator.Next()); // 2
    Console.WriteLine(generator.Next()); // 3
    
  • Random

    using ArturRios.Util.Random;
    var n   = CustomRandom.NumberFromRng(1, 10);
    var n2  = CustomRandom.NumberFromSystemRandom(0, 100, differentFrom: 42);
    var pwd = CustomRandom.Text(new RandomStringOptions { Length = 16 }); // all sets on by default
    var pin = CustomRandom.Text(new RandomStringOptions
    {
        Length = 6, IncludeLowercase = false, IncludeUppercase = false, IncludeSpecialCharacters = false
    });
    
  • RegularExpressions

    using ArturRios.Util.RegularExpressions;
    var isEmail  = RegexCollection.Email().IsMatch("john@doe.com");
    var stripped = RegexCollection.HasNumber().Remove("abc123def"); // "abcdef"
    
  • Text

    using ArturRios.Util.Text;
    var missing  = "ab1".Missing(CharacterClasses.Upper | CharacterClasses.Special); // Upper | Special
    var ok       = EmailAddress.TryNormalize("MA@Hostname.COM", out var address);    // "MA@hostname.com"
    

Detailed documentation

Full API reference, class diagrams, and usage examples:

Testing

The test suite is xUnit, and every test is named with the Given / When / Then pattern. Every test class carries a Category trait, so the two kinds can be run — and reported — separately:

dotnet test src/ArturRios.Util.sln --filter "Category=Unit"
dotnet test src/ArturRios.Util.sln --filter "Category=Functional"

Unit tests exercise the code in isolation against test doubles. Functional tests read and write real files on disk and drive HttpGateway against a real HTTP server on the loopback interface. CI runs the two as separate jobs, and both must pass before a pull request can be merged.

Versioning

Semantic Versioning (SemVer). Breaking changes result in a new major version. New methods or non-breaking behavior changes increment the minor version; fixes or tweaks increment the patch.

Build, test and publish

Use the official .NET CLI to build, test and publish the project and Git for source control. If you want, optional helper toolsets I built to facilitate these tasks are available:

This project is licensed under the MIT License. A copy of the license is available at LICENSE in the repository.


Collections

ANSI colour escape sequences and the character pools that random string generation and validation draw from.

Console

Helpers for writing formatted output to the system console.

Flow Control

Conditions that collect every failure before throwing, a reusable retry policy, and an exponential-backoff waiter with jitter.

Hashing

Argon2id password hashing with configurable cost parameters and a constant-time comparison.

Http

A typed HttpClient wrapper that returns status, headers and a deserialized body in a single envelope.

IO

Synchronous and asynchronous file readers for text, lines, delimited data and JSON.

Math

Primality tests for every built-in integer type and BigInteger, plus a generic prime generator.

Random

Cryptographically strong random numbers and strings, with optional exclusion constraints.

Regular Expressions

Source-generated compiled regular expressions for email and character-class checks, with a match timeout.

Text

Allocation-free character class checks and email normalization, offered alongside the equivalent regex patterns.