Table of Contents

Property SelectedFrame

Namespace
Alternet.Scripter.Debugger.UI
Assembly
Alternet.Scripter.Debugger.UI.v9.dll

SelectedFrame

Gets a currently selected stack frame.

[Browsable(false)]
public StackFrame SelectedFrame { get; }

Property Value

StackFrame

Examples

Here is how to use a SelectedFrame in the C# code:

using System;

using Alternet.Scripter.Debugger;
using Alternet.Scripter.Debugger.UI;

public partial class Form1 : Form
{
    private CallStack callStackControl;
    private ScriptDebugger debugger;
    private void Form1_Load(object sender, EventArgs e)
    {
        debugger = new ScriptDebugger();
        callStackControl = new CallStack();
        callStackControl.Dock = System.Windows.Forms.DockStyle.Fill;
        callStackControl.Debugger = debugger;
    }


    private void Button_Click(object sender, EventArgs e)
    {
        System.Windows.Forms.MessageBox.Show(GetCallStackString(callStackControl.SelectedFrame));
    }

    private string GetCallStackString(StackFrame frame)
    {
        string result = string.Empty;
        if (frame == null)
        {
            return result;
        }

        string methodName = frame.Name;
        int posStart = frame.Name.IndexOf('(');
        int posEnd = frame.Name.IndexOf(')');
        if ((posStart >= 0) && (posStart < posEnd))
            methodName = frame.Name.Substring(0, posStart - 1).Trim();

        string line = frame.Line != null ? frame.Line.ToString() : string.Empty;

        result = methodName;
        if (frame.File != null && frame.Line != null)
        {
            IList<string> parameters = new List<string>();

            var scopeResolver = debugger?.ScopeResolutionService;
            if (scopeResolver != null)
                scopeResolver.GetMethodName(frame.File, new Point(0, frame.Line.Value - 1), parameters, true, true);

            string paramstring = string.Empty;
            foreach (var parameter in parameters)
                paramstring += (paramstring != string.Empty) ? string.Format(", {0}", parameter) : parameter;

            if (paramstring != string.Empty)
                result += string.Format("({0})", paramstring);

            if (line != string.Empty)
                result += string.Format(" Line {0}", line);
        }

        return result;
    }
}

Here is how to use a SelectedFrame in the Visual Basic code:

Imports System

Imports Alternet.Scripter.Debugger
Imports Alternet.Scripter.Debugger.UI

Partial Public Class Form1
    Inherits Form
    Private callStackControl As CallStack
    Private debugger As ScriptDebugger
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        debugger = New ScriptDebugger()
        callStackControl = New CallStack()
        callStackControl.Dock = Windows.Forms.DockStyle.Fill
        callStackControl.Debugger = debugger
    End Sub


    Private Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
        Windows.Forms.MessageBox.Show(GetCallStackString(callStackControl.SelectedFrame))
    End Sub

    Private Function GetCallStackString(ByVal frame As StackFrame) As String
        Dim result = String.Empty
        If frame Is Nothing Then
            Return result
        End If

        Dim methodName As String = frame.Name
        Dim posStart As Integer = frame.Name.IndexOf("("c)
        Dim posEnd As Integer = frame.Name.IndexOf(")"c)
        If posStart >= 0 AndAlso posStart < posEnd Then methodName = frame.Name.Substring(0, posStart - 1).Trim()

        Dim line As String = If(frame.Line IsNot Nothing, frame.Line.ToString(), String.Empty)

        result = methodName
        If frame.File IsNot Nothing AndAlso frame.Line IsNot Nothing Then
            Dim parameters As IList(Of String) = New List(Of String)()

            Dim scopeResolver = debugger?.ScopeResolutionService
            If scopeResolver IsNot Nothing Then scopeResolver.GetMethodName(frame.File, New Point(0, frame.Line.Value - 1), parameters, True, True)

            Dim paramstring = String.Empty
            For Each parameter In parameters
                paramstring += If(Not Equals(paramstring, String.Empty), String.Format(", {0}", parameter), parameter)
            Next

            If Not Equals(paramstring, String.Empty) Then result += String.Format("({0})", paramstring)

            If Not Equals(line, String.Empty) Then result += String.Format(" Line {0}", line)
        End If

        Return result
    End Function
End Class

Remarks

The SelectedFrame property can be changed by clicking on the appropriate stack frame in the StackFrame list displayed by this control.