Exemple #1
0
        public static IEnumerable <TreeNode> LazyGetItemsOfIList(Expression targetObject)
        {
            // This is needed for expanding IEnumerable<T>

            var type = new SimpleType()
            {
                Identifier = typeof(IList).FullName
            };

            type.AddAnnotation(typeof(IList));

            targetObject = new CastExpression()
            {
                Expression = targetObject.Clone(), Type = type
            };

            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);
                }
            }
        }
        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(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(arrayTarget, new ArrayDimensions(newDims), originalBounds));
            }
            yield break;
        }