Microsoft.Scripting.Debugging.DebugFrame.GetLocalsScope C# (CSharp) Method

GetLocalsScope() private method

private GetLocalsScope ( ) : object>.IDictionary
return object>.IDictionary
        internal IDictionary<object, object> GetLocalsScope() {
            ScopeData scopeData = CurrentScopeData;
            IDictionary<object, object> scope = scopeData.Scope;
            if (scope == null) {
                Debug.Assert(_liftedLocals != null);

                List<string> visibleSymbols = new List<string>();
                List<VariableInfo> visibleLocals = new List<VariableInfo>();

                // Add parameters
                for (int i = 0; i < _funcInfo.Variables.Count; i++) {
                    if (_funcInfo.Variables[i].IsParameter && !_funcInfo.Variables[i].Hidden) {
                        visibleSymbols.Add(_funcInfo.Variables[i].Name);
                        visibleLocals.Add(_funcInfo.Variables[i]);
                    }
                }

                // Add locals
                foreach (VariableInfo varInfo in LocalsInCurrentScope) {
                    if (!varInfo.Hidden) {
                        visibleSymbols.Add(varInfo.Name);
                        visibleLocals.Add(varInfo);
                    }
                }

                IRuntimeVariables scopedLocals = new ScopedRuntimeVariables(visibleLocals, _liftedLocals);

                scope = new LocalsDictionary(scopedLocals, visibleSymbols.ToArray());

                scopeData.Scope = scope;
            }

            return scope;
        }

Usage Example

        void IDebugCallback.OnDebugEvent(TraceEventKind kind, DebugThread thread, FunctionInfo functionInfo, int sequencePointIndex, int stackDepth, object payload)
        {
            ITraceCallback traceCallback = _traceCallback;

            if (traceCallback != null)
            {
                // $TODO: what if the callback throws an exception? should we swallow it?
                var curThread = _traceFrame.Value;
                try {
                    if (kind == TraceEventKind.FrameExit || kind == TraceEventKind.ThreadExit)
                    {
                        traceCallback.OnTraceEvent(
                            kind,
                            kind == TraceEventKind.FrameExit ? functionInfo.Name : null,
                            null,
                            SourceSpan.None,
                            null,
                            payload,
                            functionInfo != null ? functionInfo.CustomPayload : null
                            );
                    }
                    else
                    {
                        DebugFrame leafFrame = thread.GetLeafFrame();
                        _traceFrame.Value = leafFrame;
                        Debug.Assert(sequencePointIndex >= 0 && sequencePointIndex < functionInfo.SequencePoints.Length);
                        DebugSourceSpan sourceSpan = functionInfo.SequencePoints[sequencePointIndex];
                        traceCallback.OnTraceEvent(
                            kind,
                            functionInfo.Name,
                            sourceSpan.SourceFile.Name,
                            sourceSpan.ToDlrSpan(),
                            () => { return(leafFrame.GetLocalsScope()); },
                            payload,
                            functionInfo.CustomPayload
                            );
                    }
                } finally {
                    _traceFrame.Value = curThread;
                }
            }
        }