From 43c92b54e549c4f22a7c35244dbf756a1e421811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= <3283596+samtrion@users.noreply.github.com> Date: Tue, 3 Dec 2019 15:36:58 +0100 Subject: [PATCH] Simplified GetPrefix `in` detection (#95) --- .../EnhancedStackTrace.Frames.cs | 33 +++++-------------- .../Internal/ReflectionHelper.cs | 8 ----- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs b/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs index 2469de4..a4b4a71 100644 --- a/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs +++ b/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs @@ -509,27 +509,20 @@ namespace System.Diagnostics return -1; } - private static string GetPrefix(ParameterInfo parameter, Type parameterType) + private static string GetPrefix(ParameterInfo parameter) { if (parameter.IsOut) { return "out"; } - if (parameterType != null && parameterType.IsByRef) + if (parameter.IsIn) { - var attribs = parameter.GetCustomAttributes(inherit: false); - if (attribs?.Length > 0) - { - foreach (var attrib in attribs) - { - if (attrib is Attribute att && att.GetType().IsReadOnlyAttribute()) - { - return "in"; - } - } - } + return "in"; + } + if (parameter.ParameterType.IsByRef) + { return "ref"; } @@ -538,18 +531,8 @@ namespace System.Diagnostics private static ResolvedParameter GetParameter(ParameterInfo parameter) { + var prefix = GetPrefix(parameter); var parameterType = parameter.ParameterType; - var prefix = GetPrefix(parameter, parameterType); - - if (parameterType == null) - { - return new ResolvedParameter - { - Prefix = prefix, - Name = parameter.Name, - ResolvedType = parameterType, - }; - } if (parameterType.IsGenericType) { @@ -625,7 +608,7 @@ 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 diff --git a/src/Ben.Demystifier/Internal/ReflectionHelper.cs b/src/Ben.Demystifier/Internal/ReflectionHelper.cs index 7280b05..c8467fd 100644 --- a/src/Ben.Demystifier/Internal/ReflectionHelper.cs +++ b/src/Ben.Demystifier/Internal/ReflectionHelper.cs @@ -14,14 +14,6 @@ namespace System.Diagnostics.Internal { private static PropertyInfo tranformerNamesLazyPropertyInfo; - /// - /// Returns true if is System.Runtime.CompilerServices.IsReadOnlyAttribute. - /// - public static bool IsReadOnlyAttribute(this Type type) - { - return type.Namespace == "System.Runtime.CompilerServices" && type.Name == "IsReadOnlyAttribute"; - } - /// /// Returns true if the is a value tuple type. ///