66using System . Collections . Generic ;
77using System . Diagnostics ;
88using System . Linq ;
9+ using System . Linq . Expressions ;
910using System . Management . Automation ;
1011using System . Reflection ;
1112using Microsoft . Extensions . Logging ;
@@ -27,7 +28,7 @@ internal class VariableDetails : VariableDetailsBase
2728 /// </summary>
2829 public const string DollarPrefix = "$" ;
2930
30- private object valueObject ;
31+ protected object valueObject ;
3132 private VariableDetails [ ] cachedChildren ;
3233
3334 #endregion
@@ -366,10 +367,23 @@ private VariableDetails[] GetChildren(object obj, ILogger logger)
366367
367368 return childVariables . ToArray ( ) ;
368369 }
369-
370- private static void AddDotNetProperties ( object obj , List < VariableDetails > childVariables )
370+ protected static void AddDotNetProperties ( object obj , List < VariableDetails > childVariables , bool noRawView = false )
371371 {
372372 Type objectType = obj . GetType ( ) ;
373+
374+ // For certain array or dictionary types, we want to hide additional properties under a "raw view" header
375+ // to reduce noise. This is inspired by the C# vscode extension.
376+ if ( ! noRawView &&
377+ (
378+ obj is IEnumerable
379+ || obj is IDictionary
380+ )
381+ )
382+ {
383+ childVariables . Add ( new VariableDetailsRawView ( obj ) ) ;
384+ return ;
385+ }
386+
373387 var properties =
374388 objectType . GetProperties (
375389 BindingFlags . Public | BindingFlags . Instance ) ;
@@ -424,4 +438,19 @@ public override string ToString()
424438 }
425439 }
426440 }
441+
442+ /// <summary>
443+ /// A VariableDetails that only returns the raw view properties of the object, rather than its values.
444+ /// </summary>
445+ internal class VariableDetailsRawView : VariableDetails
446+ {
447+ private const string RawViewName = "Raw View" ;
448+ public VariableDetailsRawView ( object value ) : base ( RawViewName , value ) { }
449+ public override VariableDetailsBase [ ] GetChildren ( ILogger logger )
450+ {
451+ List < VariableDetails > childVariables = new ( ) ;
452+ AddDotNetProperties ( valueObject , childVariables , noRawView : true ) ;
453+ return childVariables . ToArray ( ) ;
454+ }
455+ }
427456}
0 commit comments