Files
spectre.console/src/Spectre.Console/Extensions/ExceptionExtensions.cs
Patrik Svensson 9ac41ec876 Revert commits related to modernization of code
* Revert f6e1368: "Fixes problems with extension blocks and params keyword"
* Revert 7965168: "Add modernization commit to .git-blame-ignore-revs"
* Revert 3f57df5: "Modernization of the code base"
2026-01-08 14:40:23 +01:00

49 lines
1.6 KiB
C#

namespace Spectre.Console;
/// <summary>
/// Contains extension methods for <see cref="Exception"/>.
/// </summary>
public static class ExceptionExtensions
{
/// <summary>
/// Gets a <see cref="IRenderable"/> representation of the exception.
/// </summary>
/// <param name="exception">The exception to format.</param>
/// <param name="format">The exception format options.</param>
/// <returns>A <see cref="IRenderable"/> representing the exception.</returns>
[RequiresDynamicCode(ExceptionFormatter.AotWarning)]
public static IRenderable GetRenderable(this Exception exception, ExceptionFormats format = ExceptionFormats.Default)
{
if (exception is null)
{
throw new ArgumentNullException(nameof(exception));
}
return GetRenderable(exception, new ExceptionSettings
{
Format = format,
});
}
/// <summary>
/// Gets a <see cref="IRenderable"/> representation of the exception.
/// </summary>
/// <param name="exception">The exception to format.</param>
/// <param name="settings">The exception settings.</param>
/// <returns>A <see cref="IRenderable"/> representing the exception.</returns>
[RequiresDynamicCode(ExceptionFormatter.AotWarning)]
public static IRenderable GetRenderable(this Exception exception, ExceptionSettings settings)
{
if (exception is null)
{
throw new ArgumentNullException(nameof(exception));
}
if (settings is null)
{
throw new ArgumentNullException(nameof(settings));
}
return ExceptionFormatter.Format(exception, settings);
}
}