Property SelectedFrame
SelectedFrame
Gets a currently selected stack frame.
public StackFrame SelectedFrame { get; }
Property Value
Examples
Here is how to use a SelectedFrame in the C# code:
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows;
using Alternet.Scripter.Debugger;
using Alternet.Scripter.Debugger.UI.Wpf;
public partial class MainWindow : Window
{
private CallStack callStackControl;
private ScriptDebugger debugger;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
debugger = new ScriptDebugger();
callStackControl = new CallStack();
callStackControl.Debugger = debugger;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
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.Collections.Generic
Imports System.Diagnostics
Imports System.Drawing
Imports Alternet.Scripter.Debugger
Imports Alternet.Scripter.Debugger.UI.Wpf
Partial Public Class MainWindow
Inherits Window
Private callStackControl As CallStack
Private debugger As ScriptDebugger
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
debugger = New ScriptDebugger()
callStackControl = New CallStack()
callStackControl.Debugger = debugger
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
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.