Mono.Debugger.Languages.TargetArrayObject.GetArrayOffset C# (CSharp) Method

GetArrayOffset() protected method

protected GetArrayOffset ( TargetMemoryAccess target, int indices ) : int
target TargetMemoryAccess
indices int
return int
        protected int GetArrayOffset(TargetMemoryAccess target, int[] indices)
        {
            if (!GetArrayBounds (target))
                throw new LocationInvalidException ();

            if (indices.Length != Rank)
                throw new ArgumentException ();

            if (bounds.IsMultiDimensional) {
                for (int i = 0; i < Rank; i++) {
                    if (indices [i] < bounds.LowerBounds [i])
                        throw new ArgumentException ();
                    if (indices [i] > bounds.UpperBounds [i])
                        throw new ArgumentException ();
                }
            } else if (!bounds.IsUnbound &&
                   ((indices [0] < 0) || (indices [0] >= bounds.Length))) {
                throw new ArgumentException ();
            }

            int index = indices [0];
            for (int i = 1; i < Rank; i++) {
                int length = bounds.UpperBounds [i] - bounds.LowerBounds [i] + 1;
                index = index * length + indices [i];
            }

            return index * Type.GetElementSize (target);
        }