Exemplo n.º 1
0
        public TArray[] ReadArray(XmlDictionaryReader reader, TArgument localName, TArgument namespaceUri, int maxArrayLength)
        {
            TArray[][]? arrays = null;
            TArray[]? array;
            int arrayCount = 0;
            int totalRead  = 0;
            int count;

            if (reader.TryGetArrayLength(out count))
            {
                if (count > maxArrayLength)
                {
                    XmlExceptionHelper.ThrowMaxArrayLengthOrMaxItemsQuotaExceeded(reader, maxArrayLength);
                }

                if (count > XmlDictionaryReader.MaxInitialArrayLength)
                {
                    count = XmlDictionaryReader.MaxInitialArrayLength;
                }
            }
            else
            {
                count = 32;
            }
            while (true)
            {
                array = new TArray[count];
                int read = 0;
                while (read < array.Length)
                {
                    int actual = ReadArray(reader, localName, namespaceUri, array, read, array.Length - read);
                    if (actual == 0)
                    {
                        break;
                    }
                    read += actual;
                }
                if (totalRead > maxArrayLength - read)
                {
                    XmlExceptionHelper.ThrowMaxArrayLengthOrMaxItemsQuotaExceeded(reader, maxArrayLength);
                }
                totalRead += read;
                if (read < array.Length || reader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
                arrays ??= new TArray[32][];
                arrays[arrayCount++] = array;
                count *= 2;
            }
            if (totalRead != array.Length || arrayCount > 0)
            {
                TArray[] newArray = new TArray[totalRead];
                int      offset   = 0;
                for (int i = 0; i < arrayCount; i++)
                {
                    Array.Copy(arrays ![i], 0, newArray, offset, arrays[i].Length);
Exemplo n.º 2
0
        public TArray[] ReadArray(XmlDictionaryReader reader, TArgument localName, TArgument namespaceUri, int maxArrayLength)
        {
            TArray[][] localArray = null;
            TArray[]   array      = null;
            int        num3;
            int        num  = 0;
            int        num2 = 0;

            if (reader.TryGetArrayLength(out num3))
            {
                if (num3 > maxArrayLength)
                {
                    XmlExceptionHelper.ThrowMaxArrayLengthOrMaxItemsQuotaExceeded(reader, maxArrayLength);
                }
                if (num3 > 0xffff)
                {
                    num3 = 0xffff;
                }
            }
            else
            {
                num3 = 0x20;
            }
Label_0036:
            array = new TArray[num3];
            int offset = 0;

            while (offset < array.Length)
            {
                int num5 = this.ReadArray(reader, localName, namespaceUri, array, offset, array.Length - offset);
                if (num5 == 0)
                {
                    break;
                }
                offset += num5;
            }
            if (num2 > (maxArrayLength - offset))
            {
                XmlExceptionHelper.ThrowMaxArrayLengthOrMaxItemsQuotaExceeded(reader, maxArrayLength);
            }
            num2 += offset;
            if ((offset >= array.Length) && (reader.NodeType != XmlNodeType.EndElement))
            {
                if (localArray == null)
                {
                    localArray = new TArray[0x20][];
                }
                localArray[num++] = array;
                num3 *= 2;
                goto Label_0036;
            }
            if ((num2 == array.Length) && (num <= 0))
            {
                return(array);
            }
            TArray[] destinationArray = new TArray[num2];
            int      destinationIndex = 0;

            for (int i = 0; i < num; i++)
            {
                Array.Copy(localArray[i], 0, destinationArray, destinationIndex, localArray[i].Length);
                destinationIndex += localArray[i].Length;
            }
            Array.Copy(array, 0, destinationArray, destinationIndex, num2 - destinationIndex);
            return(destinationArray);
        }