System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadArrayAsBytes C# (CSharp) Method

ReadArrayAsBytes() private method

private ReadArrayAsBytes ( ParseRecord pr ) : void
pr ParseRecord
return void
		private void ReadArrayAsBytes(ParseRecord pr)
		{
			if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Byte)
				pr.PRnewObj = ReadBytes(pr.PRlengthA[0]);
			else if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Char)
				pr.PRnewObj = ReadChars(pr.PRlengthA[0]);
			else
			{
				int typeLength = Converter.TypeLength(pr.PRarrayElementTypeCode);

				pr.PRnewObj = Converter.CreatePrimitiveArray(pr.PRarrayElementTypeCode, pr.PRlengthA[0]);

				//pr.PRnewObj = Array.CreateInstance(pr.PRarrayElementType, pr.PRlengthA[0]);
				BCLDebug.Assert((pr.PRnewObj != null),"[BinaryParser expected a Primitive Array]");

				Array array = (Array)pr.PRnewObj;
				int arrayOffset = 0;
				if (byteBuffer == null)
					byteBuffer = new byte[chunkSize];

				while (arrayOffset < array.Length)
				{
					int numArrayItems = Math.Min(chunkSize/typeLength, array.Length-arrayOffset);
					int bufferUsed = numArrayItems*typeLength;
					ReadBytes(byteBuffer, 0, bufferUsed);
#if BIGENDIAN
					// we know that we are reading a primitive type, so just do a simple swap
					for (int i = 0; i < bufferUsed; i += typeLength) 
					{
						for (int j = 0; j < typeLength / 2; j++) 
						{
							byte tmp = byteBuffer[i + j];
							byteBuffer[i + j] = byteBuffer[i + typeLength - 1 - j];
							byteBuffer[i + typeLength - 1 - j] = tmp;
						}
					}
#endif
					Buffer.InternalBlockCopy(byteBuffer, 0, array, arrayOffset*typeLength, bufferUsed);
					arrayOffset += numArrayItems;
				}
			}
		}