Пример #1
0
 internal bool IsSequentialEquivalent(ResolvedMethod obj) =>
 IsAsync == obj.IsAsync &&
 DeclaringType == obj.DeclaringType &&
 Name == obj.Name &&
 IsLambda == obj.IsLambda &&
 Ordinal == obj.Ordinal &&
 GenericArguments == obj.GenericArguments &&
 SubMethod == obj.SubMethod;
        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;
        }
Пример #3
0
        public static ResolvedMethod GetMethodDisplayString(MethodBase originMethod)
        {
            var method = originMethod;

            var methodDisplayInfo = new ResolvedMethod {
                SubMethodBase = method
            };

            // Type name
            var type = method.DeclaringType;

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

            var isAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(type);

            if (isAsyncStateMachine || typeof(IEnumerator).IsAssignableFrom(type))
            {
                methodDisplayInfo.IsAsync = isAsyncStateMachine;

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

                methodName = method.Name;
            }
            else if (IsFSharpAsync(method))
            {
                methodDisplayInfo.IsAsync       = true;
                methodDisplayInfo.SubMethodBase = null;
                subMethodName = null;
                methodName    = null;
            }

            // 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 && d.Target is not null)
                                {
                                    if (ReferenceEquals(d.Method, originMethod) &&
                                        d.Target.ToString() == originMethod.DeclaringType?.ToString())
                                    {
                                        methodDisplayInfo.Name     = field.Name;
                                        methodDisplayInfo.IsLambda = false;
                                        method = originMethod;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }