-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90060 from warquys/CSharp-DebugInfo
Add DebugView for Array and Dictionary, based of the DebugView from the .NET Foundation
- Loading branch information
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
|
||
namespace Godot.Collections | ||
{ | ||
internal sealed class ArrayDebugView<T> | ||
{ | ||
private readonly IList<T> _array; | ||
|
||
public ArrayDebugView(IList<T> array) | ||
{ | ||
ArgumentNullException.ThrowIfNull(array); | ||
|
||
_array = array; | ||
} | ||
|
||
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] | ||
public T[] Items | ||
{ | ||
get | ||
{ | ||
var items = new T[_array.Count]; | ||
_array.CopyTo(items, 0); | ||
return items; | ||
} | ||
} | ||
} | ||
|
||
internal sealed class DictionaryDebugView<TKey, TValue> | ||
{ | ||
private readonly IDictionary<TKey, TValue> _dictionary; | ||
|
||
public DictionaryDebugView(IDictionary<TKey, TValue> dictionary) | ||
{ | ||
ArgumentNullException.ThrowIfNull(dictionary); | ||
|
||
_dictionary = dictionary; | ||
} | ||
|
||
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] | ||
public DictionaryKeyItemDebugView<TKey, TValue>[] Items | ||
{ | ||
get | ||
{ | ||
var items = new KeyValuePair<TKey, TValue>[_dictionary.Count]; | ||
var views = new DictionaryKeyItemDebugView<TKey, TValue>[_dictionary.Count]; | ||
_dictionary.CopyTo(items, 0); | ||
for (int i = 0; i < items.Length; i++) | ||
{ | ||
views[i] = new DictionaryKeyItemDebugView<TKey, TValue>(items[i]); | ||
} | ||
return views; | ||
} | ||
} | ||
} | ||
|
||
[DebuggerDisplay("{Value}", Name = "[{Key}]")] | ||
internal readonly struct DictionaryKeyItemDebugView<TKey, TValue> | ||
{ | ||
public DictionaryKeyItemDebugView(KeyValuePair<TKey, TValue> keyValue) | ||
{ | ||
Key = keyValue.Key; | ||
Value = keyValue.Value; | ||
} | ||
|
||
[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] | ||
public TKey Key { get; } | ||
|
||
[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] | ||
public TValue Value { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters