Browse Source

Debugger tooltips for IEnumerable<T>.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4822 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Martin Koníček 17 years ago
parent
commit
7a2a122631
  1. 1
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj
  2. 48
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ChildNodesOfObject.cs
  3. 34
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/IEnumerableNode.cs
  4. 33
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/IList.cs

1
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj

@ -132,6 +132,7 @@ @@ -132,6 +132,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\TreeModel\DebuggerResourceService.cs" />
<Compile Include="Src\TreeModel\IEnumerableNode.cs" />
<Compile Include="Src\Visualizers\Commands\ExpressionNodeVisualizerCommand.cs" />
<Compile Include="Src\Visualizers\Commands\GridVisualizerCommand.cs" />
<Compile Include="Src\Visualizers\Commands\IVisualizerCommandDescriptor.cs" />

48
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ChildNodesOfObject.cs

@ -4,12 +4,14 @@ @@ -4,12 +4,14 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Services;
using System.Collections;
using System.Collections.Generic;
using Debugger.MetaData;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.SharpDevelop;
using Debugger.AddIn.Visualizers.Utils;
namespace Debugger.AddIn.TreeModel
{
@ -67,13 +69,14 @@ namespace Debugger.AddIn.TreeModel @@ -67,13 +69,14 @@ namespace Debugger.AddIn.TreeModel
DebugType iListType = shownType.GetInterface(typeof(IList).FullName);
if (iListType != null) {
yield return new IListNode(targetObject, iListType);
} /*else {
DebugType iEnumerableType = shownType.GetInterface(typeof(IEnumerable).FullName);
if (iEnumerableType != null) {
yield return new IEnumerableNode(targetObject, iEnumerableType);
yield return new IListNode(targetObject);
} else {
DebugType iEnumerableType, itemType;
if (shownType.ResolveIEnumerableImplementation(out iEnumerableType, out itemType))
{
yield return new IEnumerableNode(targetObject, itemType);
}
}*/
}
foreach(TreeNode node in LazyGetMembersOfObject(targetObject, shownType, publicInstanceFlags)) {
yield return node;
@ -94,6 +97,37 @@ namespace Debugger.AddIn.TreeModel @@ -94,6 +97,37 @@ namespace Debugger.AddIn.TreeModel
members.Sort();
return members;
}
public static IEnumerable<TreeNode> LazyGetItemsOfIList(Expression targetObject)
{
int count = 0;
try {
count = GetIListCount(targetObject);
} catch (GetValueException) {
yield break;
}
for(int i = 0; i < count; i++) {
yield return new ExpressionNode(ExpressionNode.GetImageForArrayIndexer(), "[" + i + "]", targetObject.AppendIndexer(i));
}
}
/// <summary>
/// Evaluates System.Collections.ICollection.Count property on given object.
/// </summary>
/// <exception cref="GetValueException">Evaluating System.Collections.ICollection.Count on targetObject failed.</exception>
public static int GetIListCount(Expression targetObject)
{
Value list = targetObject.Evaluate(WindowsDebugger.CurrentProcess);
var iCollectionInterface = list.Type.GetInterface(typeof(ICollection).FullName);
if (iCollectionInterface == null) {
throw new GetValueException(targetObject, targetObject.PrettyPrint() + " does not implement System.Collections.ICollection");
}
PropertyInfo countProperty = iCollectionInterface.GetProperty("Count");
// Do not get string representation since it can be printed in hex
return (int)list.GetPropertyValue(countProperty).PrimitiveValue;
}
public static IEnumerable<TreeNode> PrependNode(TreeNode node, IEnumerable<TreeNode> rest)
{

34
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/IEnumerableNode.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Martin Koníček" email="martin.konicek@gmail.com"/>
// <version>$Revision$</version>
// </file>
using Debugger.MetaData;
using System;
using System.Collections.Generic;
using System.Linq;
using Debugger.AddIn.Visualizers.Utils;
using ICSharpCode.NRefactory.Ast;
namespace Debugger.AddIn.TreeModel
{
/// <summary>
/// IEnumerable node in the variable tree.
/// </summary>
public class IEnumerableNode : TreeNode
{
Expression targetObject;
Expression debugListExpression;
public IEnumerableNode(Expression targetObject, DebugType itemType)
{
this.targetObject = targetObject;
this.Name = "IEnumerable";
DebugType debugListType;
this.debugListExpression = DebuggerHelpers.CreateDebugListExpression(targetObject, itemType, out debugListType);
this.ChildNodes = Utils.LazyGetItemsOfIList(this.debugListExpression);
}
}
}

33
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/IList.cs

@ -13,41 +13,22 @@ using ICSharpCode.SharpDevelop.Services; @@ -13,41 +13,22 @@ using ICSharpCode.SharpDevelop.Services;
namespace Debugger.AddIn.TreeModel
{
public class IListNode: TreeNode
public class IListNode : TreeNode
{
Expression targetObject;
DebugType iListType;
int count;
public IListNode(Expression targetObject, DebugType iListType)
public IListNode(Expression targetObject)
{
this.targetObject = targetObject;
this.iListType = iListType;
this.Name = "IList";
this.ChildNodes = LazyGetChildNodes();
this.count = Utils.GetIListCount(this.targetObject);
this.ChildNodes = Utils.LazyGetItemsOfIList(this.targetObject);
}
public static WindowsDebugger WindowsDebugger {
get {
return (WindowsDebugger)DebuggerService.CurrentDebugger;
}
}
IEnumerable<TreeNode> LazyGetChildNodes()
{
PropertyInfo countProperty = iListType.GetInterface(typeof(ICollection).FullName).GetProperty("Count");
int count = 0;
try {
// Do not get string representation since it can be printed in hex
Value list = targetObject.Evaluate(WindowsDebugger.DebuggedProcess);
count = (int)list.GetPropertyValue(countProperty).PrimitiveValue;
} catch (GetValueException) {
yield break;
}
for(int i = 0; i < count; i++) {
yield return new ExpressionNode(ExpressionNode.GetImageForArrayIndexer(), "[" + i + "]", targetObject.AppendIndexer(i));
}
public override bool HasChildNodes {
get { return this.count > 0; }
}
}
}

Loading…
Cancel
Save