Ejemplo n.º 1
0
        public Array GetValues(int[] index, int count)
        {
            var values = targetArray.GetElements(index, count);
            var idx    = new int[index.Length];
            var array  = new ArrayList();

            for (int i = 0; i < index.Length; i++)
            {
                idx[i] = index[i];
            }

            Type commonType = null;

            for (int i = 0; i < count; i++)
            {
                var rv = ctx.Adapter.ToRawValue(ctx, new ArrayObjectSource(targetArray, idx), values.GetValue(i));
                if (commonType == null)
                {
                    commonType = rv.GetType();
                }
                else if (commonType != rv.GetType())
                {
                    commonType = typeof(void);
                }
                array.Add(rv);

                idx[idx.Length - 1]++;
            }

            if (array.Count > 0 && commonType != typeof(void))
            {
                return(array.ToArray(commonType));
            }

            return(array.ToArray());
        }
Ejemplo n.º 2
0
        public ObjectValue[] GetChildren(ObjectPath path, int firstItemIndex, int count, EvaluationOptions options)
        {
            EvaluationContext cctx = ctx.WithOptions(options);

            if (path.Length > 1)
            {
                // Looking for children of an array element
                int[]  idx = StringToIndices(path [1]);
                object obj = array.GetElement(idx);
                return(cctx.Adapter.GetObjectValueChildren(cctx, new ArrayObjectSource(array, path[1]), obj, firstItemIndex, count));
            }

            int  lowerBound;
            int  upperBound;
            bool isLastDimension;

            if (dimensions.Length > 1)
            {
                int rank = baseIndices.Length;
                lowerBound      = array.GetLowerBounds() [rank];
                upperBound      = lowerBound + dimensions [rank] - 1;
                isLastDimension = rank == dimensions.Length - 1;
            }
            else
            {
                lowerBound      = array.GetLowerBounds() [0];
                upperBound      = lowerBound + dimensions [0] - 1;
                isLastDimension = true;
            }

            int len;
            int initalIndex;

            if (!IsRange)
            {
                initalIndex = lowerBound;
                len         = upperBound + 1 - lowerBound;
            }
            else
            {
                initalIndex = firstIndex;
                len         = lastIndex - firstIndex + 1;
            }

            if (firstItemIndex == -1)
            {
                firstItemIndex = 0;
                count          = len;
            }

            // Make sure the group doesn't have too many elements. If so, divide
            int div = 1;

            while (len / div > MaxChildCount)
            {
                div *= 10;
            }

            if (div == 1 && isLastDimension)
            {
                // Return array elements

                ObjectValue[] values  = new ObjectValue [count];
                ObjectPath    newPath = new ObjectPath("this");

                int[] curIndex = new int [baseIndices.Length + 1];
                Array.Copy(baseIndices, curIndex, baseIndices.Length);
                string curIndexStr = IndicesToString(baseIndices);
                if (baseIndices.Length > 0)
                {
                    curIndexStr += ",";
                }
                curIndex [curIndex.Length - 1] = initalIndex + firstItemIndex;
                var elems = array.GetElements(curIndex, System.Math.Min(values.Length, upperBound - lowerBound + 1));

                for (int n = 0; n < values.Length; n++)
                {
                    int         index = n + initalIndex + firstItemIndex;
                    string      sidx  = curIndexStr + index;
                    ObjectValue val;
                    string      ename = "[" + sidx.Replace(",", ", ") + "]";
                    if (index > upperBound)
                    {
                        val = ObjectValue.CreateUnknown(sidx);
                    }
                    else
                    {
                        curIndex [curIndex.Length - 1] = index;
                        val = cctx.Adapter.CreateObjectValue(cctx, this, newPath.Append(sidx), elems.GetValue(n), ObjectValueFlags.ArrayElement);
                        if (elems.GetValue(n) != null && !cctx.Adapter.IsNull(cctx, elems.GetValue(n)))
                        {
                            TypeDisplayData tdata = cctx.Adapter.GetTypeDisplayData(cctx, cctx.Adapter.GetValueType(cctx, elems.GetValue(n)));
                            if (!string.IsNullOrEmpty(tdata.NameDisplayString))
                            {
                                try {
                                    ename = cctx.Adapter.EvaluateDisplayString(cctx, elems.GetValue(n), tdata.NameDisplayString);
                                } catch (MissingMemberException) {
                                    // missing property or otherwise malformed DebuggerDisplay string
                                }
                            }
                        }
                    }
                    val.Name   = ename;
                    values [n] = val;
                }
                return(values);
            }

            if (!isLastDimension && div == 1)
            {
                // Return an array element group for each index

                var list = new List <ObjectValue> ();
                for (int i = 0; i < count; i++)
                {
                    int         index = i + initalIndex + firstItemIndex;
                    ObjectValue val;

                    // This array must be created at every call to avoid sharing
                    // changes with all array groups
                    int[] curIndex = new int [baseIndices.Length + 1];
                    Array.Copy(baseIndices, curIndex, baseIndices.Length);
                    curIndex [curIndex.Length - 1] = index;

                    if (index > upperBound)
                    {
                        val = ObjectValue.CreateUnknown("");
                    }
                    else
                    {
                        ArrayElementGroup grp = new ArrayElementGroup(cctx, array, curIndex);
                        val = grp.CreateObjectValue();
                    }
                    list.Add(val);
                }
                return(list.ToArray());
            }
            else
            {
                // Too many elements. Split the array.

                // Don't make divisions of 10 elements, min is 100
                if (div == 10)
                {
                    div = 100;
                }

                // Create the child groups
                int i = initalIndex + firstItemIndex;
                len += i;
                var list = new List <ObjectValue> ();
                while (i < len)
                {
                    int end = i + div - 1;
                    if (end >= len)
                    {
                        end = len - 1;
                    }
                    ArrayElementGroup grp = new ArrayElementGroup(cctx, array, baseIndices, i, end);
                    list.Add(grp.CreateObjectValue());
                    i += div;
                }
                return(list.ToArray());
            }
        }