Ejemplo n.º 1
0
        static bool GetCallstack(ref List <LogStackFrame> callstack, out LogStackFrame originatingSourceLocation)
        {
            callstack.Clear();
            StackTrace stackTrace = new StackTrace(true);       // get call stack

            StackFrame[] stackFrames = stackTrace.GetFrames();  // get method calls (frames)

            bool encounteredIgnoredMethodPreviously = false;

            originatingSourceLocation = null;

            // Iterate backwards over stackframes; this enables us to show the "first" ignored Unity method if need be, but hide subsequent ones
            for (int i = stackFrames.Length - 1; i >= 0; i--)
            {
                StackFrame stackFrame = stackFrames[i];

                var method = stackFrame.GetMethod();
                if (method.IsDefined(typeof(LogUnityOnly), true))
                {
                    return(true);
                }
                if (!method.IsDefined(typeof(StackTraceIgnore), true))
                {
                    IgnoredUnityMethod.Mode showHideMode = ShowOrHideMethod(method);

                    bool setOriginatingSourceLocation = (showHideMode == IgnoredUnityMethod.Mode.Show);

                    if (showHideMode == IgnoredUnityMethod.Mode.ShowIfFirstIgnoredMethod)
                    {
                        // "show if first ignored" methods are part of the stack trace only if no other ignored methods have been encountered already
                        if (!encounteredIgnoredMethodPreviously)
                        {
                            encounteredIgnoredMethodPreviously = true;
                            showHideMode = IgnoredUnityMethod.Mode.Show;
                        }
                        else
                        {
                            showHideMode = IgnoredUnityMethod.Mode.Hide;
                        }
                    }

                    if (showHideMode == IgnoredUnityMethod.Mode.Show)
                    {
                        var logStackFrame = new LogStackFrame(stackFrame);

                        callstack.Add(logStackFrame);

                        if (setOriginatingSourceLocation)
                        {
                            originatingSourceLocation = logStackFrame;
                        }
                    }
                }
            }

            // Callstack has been processed backwards -- correct order for presentation
            callstack.Reverse();

            return(false);
        }
Ejemplo n.º 2
0
        static bool GetCallstack(ref List <LogStackFrame> callstack, out LogStackFrame originatingSourceLocation)
        {
            callstack.Clear();
            StackTrace stackTrace = new StackTrace(true);                   // get call stack

            StackFrame[] stackFrames = stackTrace.GetFrames();              // get method calls (frames)

            bool encounteredIgnoredMethodPreviously = false;

            originatingSourceLocation = null;

            for (int i = stackFrames.Length - 1; i >= 0; i--)
            {
                StackFrame stackFrame = stackFrames[i];

                var method = stackFrame.GetMethod();
                if (method.IsDefined(typeof(LogUnityOnly), true))
                {
                    return(true);
                }
                if (!method.IsDefined(typeof(StackTraceIgnore), true))
                {
                    IgnoredUnityMethod.Mode showHideMode = ShowOrHideMethod(method);

                    bool setOriginatingSourceLocation = (showHideMode == IgnoredUnityMethod.Mode.Show);

                    if (showHideMode == IgnoredUnityMethod.Mode.ShowIfFirstIgnoredMethod)
                    {
                        if (!encounteredIgnoredMethodPreviously)
                        {
                            encounteredIgnoredMethodPreviously = true;
                            showHideMode = IgnoredUnityMethod.Mode.Show;
                        }
                        else
                        {
                            showHideMode = IgnoredUnityMethod.Mode.Hide;
                        }
                    }

                    if (showHideMode == IgnoredUnityMethod.Mode.Show)
                    {
                        var logStackFrame = new LogStackFrame(stackFrame);

                        callstack.Add(logStackFrame);

                        if (setOriginatingSourceLocation)
                        {
                            originatingSourceLocation = logStackFrame;
                        }
                    }
                }
            }

            // Callstack has been processed backwards -- correct order for presentation
            callstack.Reverse();

            return(false);
        }