Ejemplo n.º 1
0
        internal EnhancedStackFrame(StackFrame stackFrame, ResolvedMethod methodInfo, string fileName, int lineNumber, int colNumber)
            : base(fileName, lineNumber, colNumber)
        {
            StackFrame = stackFrame;
            MethodInfo = methodInfo;

            _fileName   = fileName;
            _lineNumber = lineNumber;
            _colNumber  = colNumber;
        }
Ejemplo n.º 2
0
 internal bool IsSequentialEquivalent(ResolvedMethod obj)
 {
     return
         (IsAsync == obj.IsAsync &&
          DeclaringType == obj.DeclaringType &&
          Name == obj.Name &&
          IsLambda == obj.IsLambda &&
          Ordinal == obj.Ordinal &&
          GenericArguments == obj.GenericArguments &&
          SubMethod == obj.SubMethod);
 }
        public static string GetMethodDisplayString(MethodBase originMethod)
        {
            return
                (CACHE.GetOrCreate(originMethod.GetHashCode() + ".GetMethodDisplayString", e =>
            {
                // Special case: no method available
                if (originMethod == null)
                {
                    return null;
                }

                var method = originMethod;

                var methodDisplayInfo = new ResolvedMethod
                {
                    SubMethodBase = method
                };

                // Type name
                var type = method.DeclaringType;

                var subMethodName = method.Name;
                var methodName = method.Name;

                if (type != null && type.IsDefined(typeof(CompilerGeneratedAttribute)) &&
                    (typeof(IAsyncStateMachine).IsAssignableFrom(type) || typeof(IEnumerator).IsAssignableFrom(type)))
                {
                    methodDisplayInfo.IsAsync = typeof(IAsyncStateMachine).IsAssignableFrom(type);

                    // Convert StateMachine methods to correct overload +MoveNext()
                    if (!TryResolveStateMachineMethod(ref method, out type))
                    {
                        methodDisplayInfo.SubMethodBase = null;
                        subMethodName = null;
                    }

                    methodName = method.Name;
                }

                // Method name
                methodDisplayInfo.MethodBase = method;
                methodDisplayInfo.Name = methodName;
                if (method.Name.IndexOf("<") >= 0)
                {
                    if (TryResolveGeneratedName(ref method, out type, out methodName, out subMethodName, out var kind,
                                                out var ordinal))
                    {
                        methodName = method.Name;
                        methodDisplayInfo.MethodBase = method;
                        methodDisplayInfo.Name = methodName;
                        methodDisplayInfo.Ordinal = ordinal;
                    }
        public static ResolvedMethod GetMethodDisplayString(MethodBase originMethod)
        {
            // Special case: no method available
            if (originMethod == null)
            {
                return(null);
            }

            var method = originMethod;

            var methodDisplayInfo = new ResolvedMethod
            {
                SubMethodBase = method
            };

            // Type name
            var type = method.DeclaringType;

            var subMethodName = method.Name;
            var methodName    = method.Name;

            if (type != null && type.IsDefined(typeof(CompilerGeneratedAttribute)) &&
                (typeof(IAsyncStateMachine).IsAssignableFrom(type) || typeof(IEnumerator).IsAssignableFrom(type)))
            {
                methodDisplayInfo.IsAsync = typeof(IAsyncStateMachine).IsAssignableFrom(type);

                // Convert StateMachine methods to correct overload +MoveNext()
                if (!TryResolveStateMachineMethod(ref method, out type))
                {
                    methodDisplayInfo.SubMethodBase = null;
                    subMethodName = null;
                }

                methodName = method.Name;
            }

            // Method name
            methodDisplayInfo.MethodBase = method;
            methodDisplayInfo.Name       = methodName;
            if (method.Name.IndexOf("<") >= 0)
            {
                if (TryResolveGeneratedName(ref method, out type, out methodName, out subMethodName, out var kind, out var ordinal))
                {
                    methodName = method.Name;
                    methodDisplayInfo.MethodBase = method;
                    methodDisplayInfo.Name       = methodName;
                    methodDisplayInfo.Ordinal    = ordinal;
                }
                else
                {
                    methodDisplayInfo.MethodBase = null;
                }

                methodDisplayInfo.IsLambda = (kind == GeneratedNameKind.LambdaMethod);

                if (methodDisplayInfo.IsLambda && type != null)
                {
                    if (methodName == ".cctor")
                    {
                        if (type.IsGenericTypeDefinition && !type.IsConstructedGenericType)
                        {
                            // TODO: diagnose type's generic type arguments from frame's "this" or something
                        }
                        else
                        {
                            var fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                            foreach (var field in fields)
                            {
                                var value = field.GetValue(field);
                                if (value is Delegate d)
                                {
                                    if (ReferenceEquals(d.Method, originMethod) &&
                                        d.Target.ToString() == originMethod.DeclaringType.ToString())
                                    {
                                        methodDisplayInfo.Name     = field.Name;
                                        methodDisplayInfo.IsLambda = false;
                                        method = originMethod;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }