From c061f764bdfe68c6b3e6f6e3914408b35b419145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= <3283596+samtrion@users.noreply.github.com> Date: Sat, 30 Nov 2019 03:11:13 +0100 Subject: [PATCH] Rearranged checks (#92) * Rearranged checks Rearranged checks so that the method is completed as quickly as possible * Typo --- .../EnhancedStackTrace.Frames.cs | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs b/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs index ff81cc7..45cbe1d 100644 --- a/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs +++ b/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs @@ -19,7 +19,7 @@ namespace System.Diagnostics { public partial class EnhancedStackTrace { - private static readonly Type StackTraceHiddenAttibuteType = Type.GetType("System.Diagnostics.StackTraceHiddenAttribute", false); + private static readonly Type StackTraceHiddenAttributeType = Type.GetType("System.Diagnostics.StackTraceHiddenAttribute", false); private static List GetFrames(Exception exception) { @@ -625,7 +625,24 @@ namespace System.Diagnostics private static bool ShowInStackTrace(MethodBase method) { Debug.Assert(method != null); + + if (StackTraceHiddenAttributeType != null) + { + // Don't show any methods marked with the StackTraceHiddenAttribute + // https://github.com/dotnet/coreclr/pull/14652 + if (IsStackTraceHidden(method)) + { + return false; + } + } + var type = method.DeclaringType; + + if (type == null) + { + return true; + } + if (type == typeof(Task<>) && method.Name == "InnerInvoke") { return false; @@ -652,22 +669,7 @@ namespace System.Diagnostics } } - if (StackTraceHiddenAttibuteType != null) - { - // Don't show any methods marked with the StackTraceHiddenAttribute - // https://github.com/dotnet/coreclr/pull/14652 - if (IsStackTraceHidden(method)) - { - return false; - } - } - - if (type == null) - { - return true; - } - - if (StackTraceHiddenAttibuteType != null) + if (StackTraceHiddenAttributeType != null) { // Don't show any types marked with the StackTraceHiddenAttribute // https://github.com/dotnet/coreclr/pull/14652 @@ -710,7 +712,7 @@ namespace System.Diagnostics { if (!memberInfo.Module.Assembly.ReflectionOnly) { - return memberInfo.GetCustomAttributes(StackTraceHiddenAttibuteType, false).Length != 0; + return memberInfo.GetCustomAttributes(StackTraceHiddenAttributeType, false).Length != 0; } EnumerableIList attributes; @@ -726,7 +728,7 @@ namespace System.Diagnostics foreach (var attribute in attributes) { // reflection-only attribute, match on name - if (attribute.AttributeType.FullName == StackTraceHiddenAttibuteType.FullName) + if (attribute.AttributeType.FullName == StackTraceHiddenAttributeType.FullName) { return true; }