private void ParseArray(ParseRecord pr)
{
long genId = pr._objectId;
if (pr._arrayTypeEnum == InternalArrayTypeE.Base64)
{
// ByteArray
pr._newObj = pr._value.Length > 0 ?
Convert.FromBase64String(pr._value) :
Array.Empty<byte>();
if (_stack.Peek() == pr)
{
_stack.Pop();
}
if (pr._objectPositionEnum == InternalObjectPositionE.Top)
{
TopObject = pr._newObj;
}
ParseRecord parentPr = (ParseRecord)_stack.Peek();
// Base64 can be registered at this point because it is populated
RegisterObject(pr._newObj, pr, parentPr);
}
else if ((pr._newObj != null) && Converter.IsWriteAsByteArray(pr._arrayElementTypeCode))
{
// Primtive typed Array has already been read
if (pr._objectPositionEnum == InternalObjectPositionE.Top)
{
TopObject = pr._newObj;
}
ParseRecord parentPr = (ParseRecord)_stack.Peek();
// Primitive typed array can be registered at this point because it is populated
RegisterObject(pr._newObj, pr, parentPr);
}
else if ((pr._arrayTypeEnum == InternalArrayTypeE.Jagged) || (pr._arrayTypeEnum == InternalArrayTypeE.Single))
{
// Multidimensional jagged array or single array
bool couldBeValueType = true;
if ((pr._lowerBoundA == null) || (pr._lowerBoundA[0] == 0))
{
if (ReferenceEquals(pr._arrayElementType, Converter.s_typeofString))
{
pr._objectA = new string[pr._lengthA[0]];
pr._newObj = pr._objectA;
couldBeValueType = false;
}
else if (ReferenceEquals(pr._arrayElementType, Converter.s_typeofObject))
{
pr._objectA = new object[pr._lengthA[0]];
pr._newObj = pr._objectA;
couldBeValueType = false;
}
else if (pr._arrayElementType != null)
{
pr._newObj = Array.CreateInstance(pr._arrayElementType, pr._lengthA[0]);
}
pr._isLowerBound = false;
}
else
{
if (pr._arrayElementType != null)
{
pr._newObj = Array.CreateInstance(pr._arrayElementType, pr._lengthA, pr._lowerBoundA);
}
pr._isLowerBound = true;
}
if (pr._arrayTypeEnum == InternalArrayTypeE.Single)
{
if (!pr._isLowerBound && (Converter.IsWriteAsByteArray(pr._arrayElementTypeCode)))
{
pr._primitiveArray = new PrimitiveArray(pr._arrayElementTypeCode, (Array)pr._newObj);
}
else if (couldBeValueType && pr._arrayElementType != null)
{
if (!pr._arrayElementType.IsValueType && !pr._isLowerBound)
{
pr._objectA = (object[])pr._newObj;
}
}
}
pr._indexMap = new int[1];
}
else if (pr._arrayTypeEnum == InternalArrayTypeE.Rectangular)
{
// Rectangle array
pr._isLowerBound = false;
if (pr._lowerBoundA != null)
{
for (int i = 0; i < pr._rank; i++)
{
if (pr._lowerBoundA[i] != 0)
{
pr._isLowerBound = true;
}
}
}
if (pr._arrayElementType != null)
{
pr._newObj = !pr._isLowerBound ?
Array.CreateInstance(pr._arrayElementType, pr._lengthA) :
Array.CreateInstance(pr._arrayElementType, pr._lengthA, pr._lowerBoundA);
}
// Calculate number of items
int sum = 1;
for (int i = 0; i < pr._rank; i++)
{
sum = sum * pr._lengthA[i];
}
pr._indexMap = new int[pr._rank];
pr._rectangularMap = new int[pr._rank];
pr._linearlength = sum;
}
else
{
throw new SerializationException(SR.Format(SR.Serialization_ArrayType, pr._arrayTypeEnum));
}
}