diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj index 4f9c4ee8c3..a40434d2d0 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj @@ -132,6 +132,7 @@ Code + diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ChildNodesOfObject.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ChildNodesOfObject.cs index 476521aac9..bc261ec708 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ChildNodesOfObject.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ChildNodesOfObject.cs @@ -4,12 +4,14 @@ // $Revision$ // +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 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 members.Sort(); return members; } + + + public static IEnumerable 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)); + } + } + + /// + /// Evaluates System.Collections.ICollection.Count property on given object. + /// + /// Evaluating System.Collections.ICollection.Count on targetObject failed. + 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 PrependNode(TreeNode node, IEnumerable rest) { diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/IEnumerableNode.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/IEnumerableNode.cs new file mode 100644 index 0000000000..e491e2ec89 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/IEnumerableNode.cs @@ -0,0 +1,34 @@ +// +// +// +// +// $Revision$ +// +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 +{ + /// + /// IEnumerable node in the variable tree. + /// + 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); + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/IList.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/IList.cs index 1d9a65b779..82d5450dab 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/IList.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/IList.cs @@ -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 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; } } } }