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.
This commit is contained in:
2026-08-31 15:39:11 +02:00
parent 0e22ffb2c5
commit 68eeeb1eda

View File

@@ -13,9 +13,31 @@ namespace DocumentService.Client.Models.Results;
/// </param>
/// <param name="Validation">
/// PDF validation result. Always populated regardless of whether extraction succeeded.
/// Use <see cref="DocumentService.Application.Common.DTOs.PdfValidationResult.IsValid"/>
/// Use <see cref="PdfValidationResult.IsValid"/>
/// to determine whether the extraction was attempted.
/// </param>
public record SwissQrCodeResult(
SwissQrCodeExtractionResult? QrCode,
PdfValidationResult Validation);
PdfValidationResult Validation)
{
/// <summary>
/// Optional convenience method for code readability. Follows the standard
/// <c>TryXxx</c> pattern (e.g. <see cref="int.TryParse(string, out int)"/>,
/// <see cref="Dictionary{TKey,TValue}.TryGetValue"/>).
/// Use it when you prefer an <c>if/else</c> branch over a null-check on <see cref="QrCode"/>;
/// it is not required – both approaches are equivalent.
/// </summary>
/// <param name="qrCode">
/// When this method returns <c>true</c>, contains the extracted QR Code data.
/// When this method returns <c>false</c>, this value is <c>null</c> and must not be used.
/// </param>
/// <returns>
/// <c>true</c> if the PDF was valid and a Swiss QR Code was successfully extracted;
/// <c>false</c> otherwise.
/// </returns>
public bool TryExtract(out SwissQrCodeExtractionResult qrCode)
{
qrCode = QrCode ?? null!;
return Validation.IsValid && QrCode is not null;
}
}