~ruther/NosSmooth

a14e7e974bf403fe1d53258ffcc5ac262ac9ff3f — Rutherther 3 years ago 70ba0dd
feat: add possibility to convert error results to string
1 files changed, 21 insertions(+), 0 deletions(-)

M Core/NosSmooth.Core/Extensions/ResultExtensions.cs
M Core/NosSmooth.Core/Extensions/ResultExtensions.cs => Core/NosSmooth.Core/Extensions/ResultExtensions.cs +21 -0
@@ 39,6 39,27 @@ public static class ResultExtensions
        logger.LogError(stringWriter.ToString());
    }

    /// <summary>
    /// Gets the full string.
    /// </summary>
    /// <param name="result">The result.</param>
    /// <returns>The final string.</returns>
    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)

Do not follow this link