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);
                }
            }
        }
Exemple #2
0
        IEnumerable <TreeNode> LazyGetChildren()
        {
            // The whole array is small - just add all elements as childs
            if (bounds.TotalElementCount <= MaxElementCount)
            {
                foreach (int[] indices in bounds.Indices)
                {
                    string imageName;
                    var    image      = ExpressionNode.GetImageForArrayIndexer(out imageName);
                    var    expression = new ExpressionNode(this, image, GetName(indices), arrayTarget.AppendIndexer(indices));
                    expression.ImageName = imageName;
                    yield return(expression);
                }
                yield break;
            }

            // Find a dimension of size at least 2
            int splitDimensionIndex = bounds.Count - 1;

            for (int i = 0; i < bounds.Count; i++)
            {
                if (bounds[i].Count > 1)
                {
                    splitDimensionIndex = i;
                    break;
                }
            }
            ArrayDimension splitDim = bounds[splitDimensionIndex];

            // Split the dimension
            int elementsPerSegment = 1;

            while (splitDim.Count > elementsPerSegment * MaxElementCount)
            {
                elementsPerSegment *= MaxElementCount;
            }
            for (int i = splitDim.LowerBound; i <= splitDim.UpperBound; i += elementsPerSegment)
            {
                List <ArrayDimension> newDims = new List <ArrayDimension>(bounds);
                newDims[splitDimensionIndex] = new ArrayDimension(i, Math.Min(i + elementsPerSegment - 1, splitDim.UpperBound));
                yield return(new ArrayRangeNode(this, arrayTarget, new ArrayDimensions(newDims), originalBounds));
            }
            yield break;
        }
Exemple #3
0
        public static IEnumerable <TreeNode> LazyGetItemsOfIList(Expression targetObject)
        {
            // This is needed for expanding IEnumerable<T>
            targetObject = new CastExpression(
                new TypeReference(typeof(IList).FullName),
                targetObject,
                CastType.Cast
                );
            int count = 0;
            GetValueException error = null;

            try {
                count = GetIListCount(targetObject);
            } 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));
            }
            else if (count == 0)
            {
                yield return(new TreeNode(null, "(empty)", null, null, null));
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    string imageName;
                    var    image      = ExpressionNode.GetImageForArrayIndexer(out imageName);
                    var    expression = new ExpressionNode(image, "[" + i + "]", targetObject.AppendIndexer(i));
                    expression.ImageName = imageName;
                    yield return(expression);
                }
            }
        }