From 68eeeb1eda015e7d2c2baee8916b10b5f834aeab Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 31 Aug 2026 15:39:11 +0200 Subject: [PATCH] Add TryExtract method to SwissQrCodeResult record Replaced the fully qualified reference to `DocumentService.Application.Common.DTOs.PdfValidationResult.IsValid` with the simpler `PdfValidationResult.IsValid`. Added a `TryExtract` method to the `SwissQrCodeResult` record to improve code readability and usability. The method follows the standard `TryXxx` pattern, allowing for an `if/else` branch instead of a direct null-check on the `QrCode` property. It returns `true` if the PDF was valid and a Swiss QR Code was successfully extracted, and `false` otherwise. --- .../Models/Results/SwissQrCodeResult.cs | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/DocumentService.Client/Models/Results/SwissQrCodeResult.cs b/DocumentService.Client/Models/Results/SwissQrCodeResult.cs index 9656353..a9e0330 100644 --- a/DocumentService.Client/Models/Results/SwissQrCodeResult.cs +++ b/DocumentService.Client/Models/Results/SwissQrCodeResult.cs @@ -13,9 +13,31 @@ namespace DocumentService.Client.Models.Results; /// /// /// PDF validation result. Always populated regardless of whether extraction succeeded. -/// Use +/// Use /// to determine whether the extraction was attempted. /// public record SwissQrCodeResult( SwissQrCodeExtractionResult? QrCode, - PdfValidationResult Validation); + PdfValidationResult Validation) +{ + /// + /// Optional convenience method for code readability. Follows the standard + /// TryXxx pattern (e.g. , + /// ). + /// Use it when you prefer an if/else branch over a null-check on ; + /// it is not required – both approaches are equivalent. + /// + /// + /// When this method returns true, contains the extracted QR Code data. + /// When this method returns false, this value is null and must not be used. + /// + /// + /// true if the PDF was valid and a Swiss QR Code was successfully extracted; + /// false otherwise. + /// + public bool TryExtract(out SwissQrCodeExtractionResult qrCode) + { + qrCode = QrCode ?? null!; + return Validation.IsValid && QrCode is not null; + } +}