Skip to content

Display DictionaryEntry as key/value pairs in debugger #1680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@ private static string GetValueStringAndType(object value, bool isExpandable, out
{
// For DictionaryEntry - display the key/value as the value.
var entry = (DictionaryEntry)value;
valueString =
string.Format(
"[{0}, {1}]",
entry.Key,
GetValueStringAndType(entry.Value, GetIsExpandable(entry.Value), out typeName));
valueString = GetValueStringAndType(entry.Value, GetIsExpandable(entry.Value), out typeName);
}
else
{
Expand Down Expand Up @@ -328,12 +324,11 @@ private VariableDetails[] GetChildren(object obj, ILogger logger)
// function that defines parameters and has been passed parameters.
// If you open the $PSBoundParameters variable node in this scenario and see nothing,
// this code is broken.
int i = 0;
foreach (DictionaryEntry entry in dictionary)
{
childVariables.Add(
new VariableDetails(
"[" + i++ + "]",
"[" + entry.Key + "]",
entry));
}
}
Expand Down
18 changes: 7 additions & 11 deletions test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -719,19 +719,15 @@ await debugService.SetLineBreakpointsAsync(
VariableDetailsBase[] childVars = debugService.GetVariables(var.Id);
// 2 variables plus "Raw View"
Assert.Equal(3, childVars.Length);
Assert.Equal("[0]", childVars[0].Name);
Assert.Equal("[1]", childVars[1].Name);

var childVarStrs = new HashSet<string>(childVars.Select(v => v.ValueString));
var expectedVars = new[] {
"[firstChild, \"Child\"]",
"[secondChild, 42]"
};
// Hashtables are unordered hence the Linq examination, examination by index is unreliable
VariableDetailsBase firstChild = Array.Find(childVars, v => v.Name == "[firstChild]");
Assert.NotNull(firstChild);
Assert.Equal("\"Child\"", firstChild.ValueString);

foreach (string expectedVar in expectedVars)
{
Assert.Contains(expectedVar, childVarStrs);
}
VariableDetailsBase secondChild = Array.Find(childVars, v => v.Name == "[secondChild]");
Assert.NotNull(secondChild);
Assert.Equal("42", secondChild.ValueString);
}

[Fact]
Expand Down