public static IEnumerable<TreeNode> LazyGetItemsOfIList(TreeNode parent, Expression targetObject) { // Add a cast, so that we are sure the expression has an indexer. // (The expression can be e.g. of type 'object' but its value is a List. // Without the cast, evaluating "expr[i]" would fail, because object does not have an indexer). targetObject = targetObject.CastToIList(); int count = 0; GetValueException error = null; try { count = targetObject.GetIListCount(); } catch (GetValueException e) { // Cannot yield a value in the body of a catch clause (CS1631) error = e; } if (error != null) { yield return new TreeNode(null, "(error)", error.Message, null, null, null); } else if (count == 0) { yield return new TreeNode(null, "(empty)", null, null, null, null); } else { for(int i = 0; i < count; i++) { string imageName; var image = ExpressionNode.GetImageForArrayIndexer(out imageName); var itemNode = new ExpressionNode(parent, image, "[" + i + "]", targetObject.AppendIndexer(i)); itemNode.ImageName = imageName; yield return itemNode; } } }
void LoadNodeCollectionContent(AbstractNode node, Expression thisObject, DebugType iListType) { thisObject = thisObject.CastToIList(); int listCount = thisObject.GetIListCount(); PropertyInfo indexerProp = iListType.GetProperty("Item"); for (int i = 0; i < listCount; i++) { Expression itemExpr = thisObject.AppendIndexer(i); PropertyNode itemNode = new PropertyNode( new ObjectGraphProperty { Name = "[" + i + "]", MemberInfo = indexerProp, Expression = itemExpr, Value = "", IsAtomic = true, TargetNode = null }); node.AddChild(itemNode); } }