mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 10:35:27 +08:00 
			
		
		
		
	Add RequiresDynamicCode attribute to exception formatter to indicate incompatability with AOT
This commit is contained in:
		
				
					committed by
					
						
						Patrik Svensson
					
				
			
			
				
	
			
			
			
						parent
						
							10773a5625
						
					
				
				
					commit
					b67af32423
				
			@@ -10,6 +10,7 @@ public static partial class AnsiConsole
 | 
				
			|||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    /// <param name="exception">The exception to write to the console.</param>
 | 
					    /// <param name="exception">The exception to write to the console.</param>
 | 
				
			||||||
    /// <param name="format">The exception format options.</param>
 | 
					    /// <param name="format">The exception format options.</param>
 | 
				
			||||||
 | 
					    [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
 | 
				
			||||||
    public static void WriteException(Exception exception, ExceptionFormats format = ExceptionFormats.Default)
 | 
					    public static void WriteException(Exception exception, ExceptionFormats format = ExceptionFormats.Default)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Console.WriteException(exception, format);
 | 
					        Console.WriteException(exception, format);
 | 
				
			||||||
@@ -20,6 +21,7 @@ public static partial class AnsiConsole
 | 
				
			|||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    /// <param name="exception">The exception to write to the console.</param>
 | 
					    /// <param name="exception">The exception to write to the console.</param>
 | 
				
			||||||
    /// <param name="settings">The exception settings.</param>
 | 
					    /// <param name="settings">The exception settings.</param>
 | 
				
			||||||
 | 
					    [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
 | 
				
			||||||
    public static void WriteException(Exception exception, ExceptionSettings settings)
 | 
					    public static void WriteException(Exception exception, ExceptionSettings settings)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Console.WriteException(exception, settings);
 | 
					        Console.WriteException(exception, settings);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,7 @@ public static partial class AnsiConsoleExtensions
 | 
				
			|||||||
    /// <param name="console">The console.</param>
 | 
					    /// <param name="console">The console.</param>
 | 
				
			||||||
    /// <param name="exception">The exception to write to the console.</param>
 | 
					    /// <param name="exception">The exception to write to the console.</param>
 | 
				
			||||||
    /// <param name="format">The exception format options.</param>
 | 
					    /// <param name="format">The exception format options.</param>
 | 
				
			||||||
 | 
					    [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
 | 
				
			||||||
    public static void WriteException(this IAnsiConsole console, Exception exception, ExceptionFormats format = ExceptionFormats.Default)
 | 
					    public static void WriteException(this IAnsiConsole console, Exception exception, ExceptionFormats format = ExceptionFormats.Default)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        console.Write(exception.GetRenderable(format));
 | 
					        console.Write(exception.GetRenderable(format));
 | 
				
			||||||
@@ -22,6 +23,7 @@ public static partial class AnsiConsoleExtensions
 | 
				
			|||||||
    /// <param name="console">The console.</param>
 | 
					    /// <param name="console">The console.</param>
 | 
				
			||||||
    /// <param name="exception">The exception to write to the console.</param>
 | 
					    /// <param name="exception">The exception to write to the console.</param>
 | 
				
			||||||
    /// <param name="settings">The exception settings.</param>
 | 
					    /// <param name="settings">The exception settings.</param>
 | 
				
			||||||
 | 
					    [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
 | 
				
			||||||
    public static void WriteException(this IAnsiConsole console, Exception exception, ExceptionSettings settings)
 | 
					    public static void WriteException(this IAnsiConsole console, Exception exception, ExceptionSettings settings)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        console.Write(exception.GetRenderable(settings));
 | 
					        console.Write(exception.GetRenderable(settings));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,7 @@ public static class ExceptionExtensions
 | 
				
			|||||||
    /// <param name="exception">The exception to format.</param>
 | 
					    /// <param name="exception">The exception to format.</param>
 | 
				
			||||||
    /// <param name="format">The exception format options.</param>
 | 
					    /// <param name="format">The exception format options.</param>
 | 
				
			||||||
    /// <returns>A <see cref="IRenderable"/> representing the exception.</returns>
 | 
					    /// <returns>A <see cref="IRenderable"/> representing the exception.</returns>
 | 
				
			||||||
 | 
					    [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
 | 
				
			||||||
    public static IRenderable GetRenderable(this Exception exception, ExceptionFormats format = ExceptionFormats.Default)
 | 
					    public static IRenderable GetRenderable(this Exception exception, ExceptionFormats format = ExceptionFormats.Default)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (exception is null)
 | 
					        if (exception is null)
 | 
				
			||||||
@@ -30,6 +31,7 @@ public static class ExceptionExtensions
 | 
				
			|||||||
    /// <param name="exception">The exception to format.</param>
 | 
					    /// <param name="exception">The exception to format.</param>
 | 
				
			||||||
    /// <param name="settings">The exception settings.</param>
 | 
					    /// <param name="settings">The exception settings.</param>
 | 
				
			||||||
    /// <returns>A <see cref="IRenderable"/> representing the exception.</returns>
 | 
					    /// <returns>A <see cref="IRenderable"/> representing the exception.</returns>
 | 
				
			||||||
 | 
					    [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
 | 
				
			||||||
    public static IRenderable GetRenderable(this Exception exception, ExceptionSettings settings)
 | 
					    public static IRenderable GetRenderable(this Exception exception, ExceptionSettings settings)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (exception is null)
 | 
					        if (exception is null)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,12 @@
 | 
				
			|||||||
namespace Spectre.Console;
 | 
					namespace Spectre.Console;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma warning disable IL2026,IL2070,IL2075,IL3050
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal static class ExceptionFormatter
 | 
					internal static class ExceptionFormatter
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    public const string AotWarning = "ExceptionFormatter is currently not supported for AOT.";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
 | 
				
			||||||
    public static IRenderable Format(Exception exception, ExceptionSettings settings)
 | 
					    public static IRenderable Format(Exception exception, ExceptionSettings settings)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (exception is null)
 | 
					        if (exception is null)
 | 
				
			||||||
@@ -398,6 +403,7 @@ internal static class ExceptionFormatter
 | 
				
			|||||||
        return builder.ToString();
 | 
					        return builder.ToString();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [RequiresDynamicCode(ExceptionFormatter.AotWarning)]
 | 
				
			||||||
    private static bool TryResolveStateMachineMethod(ref MethodBase method, out Type declaringType)
 | 
					    private static bool TryResolveStateMachineMethod(ref MethodBase method, out Type declaringType)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // https://github.com/dotnet/runtime/blob/v6.0.0/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs#L400-L455
 | 
					        // https://github.com/dotnet/runtime/blob/v6.0.0/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs#L400-L455
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user