From a14e7e974bf403fe1d53258ffcc5ac262ac9ff3f Mon Sep 17 00:00:00 2001 From: Rutherther Date: Thu, 27 Jan 2022 14:24:42 +0100 Subject: [PATCH] feat: add possibility to convert error results to string --- .../Extensions/ResultExtensions.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Core/NosSmooth.Core/Extensions/ResultExtensions.cs b/Core/NosSmooth.Core/Extensions/ResultExtensions.cs index 84bcf0f..00c8ebf 100644 --- a/Core/NosSmooth.Core/Extensions/ResultExtensions.cs +++ b/Core/NosSmooth.Core/Extensions/ResultExtensions.cs @@ -39,6 +39,27 @@ public static class ResultExtensions logger.LogError(stringWriter.ToString()); } + /// + /// Gets the full string. + /// + /// The result. + /// The final string. + public static string ToFullString(this IResult result) + { + if (result.IsSuccess) + { + throw new InvalidOperationException("The result was successful, only unsuccessful results are supported."); + } + + using StringWriter stringWriter = new StringWriter(); + using IndentedTextWriter logTextWriter = new IndentedTextWriter(stringWriter, " "); + logTextWriter.WriteLine("Encountered an error"); + logTextWriter.Indent++; + + LogResultError(logTextWriter, result); + return stringWriter.ToString(); + } + private static void LogResultError(IndentedTextWriter logTextWriter, IResult result) { switch (result.Error) -- 2.48.1