diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs index 9b5aec7031c..fb1d32c0cb3 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs @@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.CompilerServices; using Godot.NativeInterop; +using System.Diagnostics; #nullable enable @@ -16,6 +17,8 @@ namespace Godot.Collections /// interfacing with the engine. Otherwise prefer .NET collections /// such as or . /// + [DebuggerTypeProxy(typeof(ArrayDebugView))] + [DebuggerDisplay("Count = {Count}")] #pragma warning disable CA1710 // Identifiers should have correct suffix public sealed class Array : #pragma warning restore CA1710 @@ -1040,6 +1043,8 @@ namespace Godot.Collections /// such as arrays or . /// /// The type of the array. + [DebuggerTypeProxy(typeof(ArrayDebugView<>))] + [DebuggerDisplay("Count = {Count}")] [SuppressMessage("ReSharper", "RedundantExtendsListEntry")] [SuppressMessage("Naming", "CA1710", MessageId = "Identifiers should have correct suffix")] public sealed class Array<[MustBeVariant] T> : diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/DebugView.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/DebugView.cs new file mode 100644 index 00000000000..6d6eb61f8f9 --- /dev/null +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/DebugView.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Godot.Collections +{ + internal sealed class ArrayDebugView + { + private readonly IList _array; + + public ArrayDebugView(IList 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 + { + private readonly IDictionary _dictionary; + + public DictionaryDebugView(IDictionary dictionary) + { + ArgumentNullException.ThrowIfNull(dictionary); + + _dictionary = dictionary; + } + + [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] + public DictionaryKeyItemDebugView[] Items + { + get + { + var items = new KeyValuePair[_dictionary.Count]; + var views = new DictionaryKeyItemDebugView[_dictionary.Count]; + _dictionary.CopyTo(items, 0); + for (int i = 0; i < items.Length; i++) + { + views[i] = new DictionaryKeyItemDebugView(items[i]); + } + return views; + } + } + } + + [DebuggerDisplay("{Value}", Name = "[{Key}]")] + internal readonly struct DictionaryKeyItemDebugView + { + public DictionaryKeyItemDebugView(KeyValuePair keyValue) + { + Key = keyValue.Key; + Value = keyValue.Value; + } + + [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] + public TKey Key { get; } + + [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] + public TValue Value { get; } + } +} diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs index d08fad90db8..864815866ae 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Godot.NativeInterop; +using System.Diagnostics; #nullable enable @@ -14,6 +15,8 @@ namespace Godot.Collections /// typed elements allocated in the engine in C++. Useful when /// interfacing with the engine. /// + [DebuggerTypeProxy(typeof(DictionaryDebugView))] + [DebuggerDisplay("Count = {Count}")] public sealed class Dictionary : IDictionary, IReadOnlyDictionary, @@ -480,6 +483,8 @@ namespace Godot.Collections /// /// The type of the dictionary's keys. /// The type of the dictionary's values. + [DebuggerTypeProxy(typeof(DictionaryDebugView<,>))] + [DebuggerDisplay("Count = {Count}")] public class Dictionary<[MustBeVariant] TKey, [MustBeVariant] TValue> : IDictionary, IReadOnlyDictionary, diff --git a/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj b/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj index d54942e6548..d4c11da963c 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj +++ b/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj @@ -77,6 +77,7 @@ +