Skip to Content
TUtilityQuick start

Quick start

On this page

Examples use .NET 10: install TUtility.Core for caches and CRC, TUtility for operation results, and TUtility.App with its generator for modular hosting.

Core tools

dotnet new console -n UtilityDemo -f net10.0 cd UtilityDemo dotnet add package TUtility.Core

Place this in Program.cs:

using TUtility; using TUtility.Caching; using var cache = new MemoryCache<string, string>(); cache.Set("device:P-001", "Pump", expire: 60); if (cache.TryGetValue("device:P-001", out var name)) { Console.WriteLine(name); } byte[] payload = [0x01, 0x03, 0x00, 0x00, 0x00, 0x02]; var crc = CrcHelper.Crc16Only(payload.AsSpan()); Console.WriteLine(Convert.ToHexString(crc));

Run:

dotnet run

Expected output:

Pump C40B

Cache TTLs use seconds; disposal ends the cleanup timer. CRC returns two checksum bytes without the original payload. Assemble frames and order bytes according to the target protocol.

Operation results

dotnet add package TUtility
using TUtility; OperResult<int> result = OperResult.CreateSuccessResult(42); if (result.IsSuccess) { Console.WriteLine(result.Content); }

Replace Program.cs with this fragment and run dotnet run to print 42. OperResult belongs to TUtility rather than Core. Its success-code convention differs from TWebApi’s 200. Check IsSuccess before consuming failed-result content; see results.

Modular hosts

dotnet add package TUtility.App dotnet add package TUtility.Generator dotnet add package Microsoft.Extensions.Hosting

Call the generated AppStartupRunner during service registration and initialization, then run the host. See AppStartup for complete code. Plain utility calls do not require a Host.

Apply the tools in your project

TaskChapterIntegration decision
Cache devices or query resultsCaches and poolsTTL units, capacity cleanup and disposal
Process operations concurrentlyAsync coordinationShare a limiter across callers and release each acquired permit
Run periodic maintenanceTimerXReentrancy, time zone and operations still running at shutdown
Exchange JSON dataSerializationNaming, long integers and required resolvers

Source: TUtility repository . src contains runtime libraries, analyzer contains analyzers and generators, and test contains examples and tests.