Skip to Content
TUtilityOperation results and paging

Operation results and paging

On this page

Success state

OperResult and OperResult<T> are structs in the TUtility package, with a nullable integer OperCode.

Install TUtility using the quick start and put this program in Program.cs. The same caller handles an existing and a missing device. Its failure branch does not continue using Content.

using TUtility; var devices = new Dictionary<string, string>(StringComparer.Ordinal) { ["P-001"] = "Pump" }; foreach (var code in new[] { "P-001", "P-404" }) { OperResult<string> result = devices.TryGetValue(code, out var name) ? OperResult.CreateSuccessResult(name) : new OperResult<string>($"Device {code} was not found."); if (!result.IsSuccess) { Console.WriteLine($"Failed ({result.OperCode}): {result.ErrorMessage}"); continue; } Console.WriteLine($"Found: {code}, {result.Content}"); }

Expected output:

Found: P-001, Pump Failed (500): Device P-404 was not found.

The string error constructor sets OperCode = 500. Non-generic results expose static values such as Success, Timeout, Cancel and UnknownFail. Branch on IsSuccess:

StateCaller interpretation
OperCode is null or 0Business success; check content when the operation requires it
Nonzero OperCodeBusiness failure; handle the error before deciding whether to retry
default(OperResult<T>)Default success, rather than “not executed”; use separate execution state or a nullable result
WebApi UnifyResult.CodeResponse status with 200 for success; see WebApi conversion rules

Content and exceptions

Content carries typed output. ErrorMessage describes failure. Exception retains the in-process exception and is ignored by JSON. Assignments copy the struct, while referenced objects remain shared.

Success does not validate non-null content. Converting to a non-generic result retains only status and error information.

Paging models

BasePageInput defaults to Current = 1 and Size = 10. Core’s PagedList<T> contains:

FieldMeaning
Current / SizePage number and page size
RecordsCurrent List<T>
Total / PagesInteger row and page counts
HasPrevPages / HasNextPagesAdjacent-page flags

This DTO does not execute queries, enforce size limits or calculate every field automatically. TORM paging methods populate query results. Manual construction must keep fields consistent.

Complete example: page two and its metadata

This independent program demonstrates paging over in-memory data:

using TUtility; string[] devices = ["P-001", "P-002", "P-003", "P-004", "P-005"]; var input = new BasePageInput { Current = 2, Size = 2 }; var total = devices.Length; var pages = (total + input.Size - 1) / input.Size; var page = new PagedList<string> { Current = input.Current, Size = input.Size, Total = total, Pages = pages, HasPrevPages = input.Current > 1, HasNextPages = input.Current < pages, Records = devices.Skip((input.Current - 1) * input.Size).Take(input.Size).ToList() }; Console.WriteLine($"Page: {page.Current}/{page.Pages}, total: {page.Total}"); Console.WriteLine($"Records: {string.Join(", ", page.Records)}"); Console.WriteLine($"Previous: {page.HasPrevPages}, next: {page.HasNextPages}");

Expected output:

Page: 2/3, total: 5 Records: P-003, P-004 Previous: True, next: True

Validate external input for Current >= 1 and Size > 0, and limit page size. The data access layer handles stable ordering, database counts and paging.

Cursor pagination uses a different contract. TORM’s CursorPage<T> returns NextCursor and HasMore; it should not invent an unknown total. See TORM queries.