internal void Init() { this.PRparseTypeEnum = InternalParseTypeE.Empty; this.PRobjectTypeEnum = InternalObjectTypeE.Empty; this.PRarrayTypeEnum = InternalArrayTypeE.Empty; this.PRmemberTypeEnum = InternalMemberTypeE.Empty; this.PRmemberValueEnum = InternalMemberValueE.Empty; this.PRobjectPositionEnum = InternalObjectPositionE.Empty; this.PRname = null; this.PRnameXmlKey = null; this.PRxmlNameSpace = null; this.PRisParsed = false; this.PRisProcessAttributes = false; this.PRvalue = null; this.PRkeyDt = null; this.PRdtType = null; this.PRassemblyName = null; this.PRdtTypeCode = InternalPrimitiveTypeE.Invalid; this.PRisEnum = false; this.PRobjectId = 0L; this.PRidRef = 0L; this.PRarrayElementTypeString = null; this.PRarrayElementType = null; this.PRisArrayVariant = false; this.PRarrayElementTypeCode = InternalPrimitiveTypeE.Invalid; this.PRprimitiveArrayTypeString = null; this.PRrank = 0; this.PRlengthA = null; this.PRpositionA = null; this.PRlowerBoundA = null; this.PRupperBoundA = null; this.PRindexMap = null; this.PRmemberIndex = 0; this.PRlinearlength = 0; this.PRrectangularMap = null; this.PRisLowerBound = false; this.PRtopId = 0L; this.PRheaderId = 0L; this.PRisHeaderRoot = false; this.PRisAttributesProcessed = false; this.PRisMustUnderstand = false; this.PRparseStateEnum = InternalParseStateE.Initial; this.PRisWaitingForNestedObject = false; this.PRisValueTypeFixup = false; this.PRnewObj = null; this.PRobjectA = null; this.PRprimitiveArray = null; this.PRobjectInfo = null; this.PRisRegistered = false; this.PRisXmlAttribute = false; }
// Writes out an array private void WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo) { InternalST.Soap( this, "WriteArray Entry ",objectInfo.obj," ",objectInfo.objectId); bool isAllocatedMemberNameInfo = false; if (memberNameInfo == null) { memberNameInfo = TypeToNameInfo(objectInfo); memberNameInfo.NIisTopLevelObject = true; isAllocatedMemberNameInfo = true; } memberNameInfo.NIisArray = true; long objectId = objectInfo.objectId; memberNameInfo.NIobjectId = objectInfo.objectId; // Get array type System.Array array = (System.Array)objectInfo.obj; //Type arrayType = array.GetType(); Type arrayType = objectInfo.objectType; // Get type of array element Type arrayElemType = arrayType.GetElementType(); WriteObjectInfo arrayElemObjectInfo = WriteObjectInfo.Serialize(arrayElemType, m_surrogates, m_context, serObjectInfoInit, m_formatterConverter, (memberObjectInfo == null) ? null : memberObjectInfo.typeAttributeInfo); arrayElemObjectInfo.assemId = GetAssemblyId(arrayElemObjectInfo); NameInfo arrayElemTypeNameInfo = null; NameInfo arrayNameInfo = ArrayTypeToNameInfo(objectInfo, out arrayElemTypeNameInfo); arrayNameInfo.NIobjectId = objectId; arrayNameInfo.NIisArray = true; arrayElemTypeNameInfo.NIobjectId = objectId; arrayElemTypeNameInfo.NItransmitTypeOnMember = memberNameInfo.NItransmitTypeOnMember; arrayElemTypeNameInfo.NItransmitTypeOnObject = memberNameInfo.NItransmitTypeOnObject; arrayElemTypeNameInfo.NIisParentTypeOnObject = memberNameInfo.NIisParentTypeOnObject; // Get rank and length information int rank = array.Rank; int[] lengthA = new int[rank]; int[] lowerBoundA = new int[rank]; int[] upperBoundA = new int[rank]; for (int i=0; i<rank; i++) { lengthA[i] = array.GetLength(i); lowerBoundA[i] = array.GetLowerBound(i); upperBoundA[i] = array.GetUpperBound(i); } InternalArrayTypeE arrayEnum; if (arrayElemType.IsArray) { if (rank == 1) arrayEnum = InternalArrayTypeE.Jagged; else arrayEnum = InternalArrayTypeE.Rectangular; } else if (rank == 1) arrayEnum = InternalArrayTypeE.Single; else arrayEnum = InternalArrayTypeE.Rectangular; InternalST.Soap( this, "WriteArray ArrayInfo type ",arrayType," rank ",rank); // Byte array if ((arrayElemType == Converter.typeofByte) && (rank == 1) && (lowerBoundA[0] == 0)) { serWriter.WriteObjectByteArray(memberNameInfo, arrayNameInfo, arrayElemObjectInfo, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0], (byte[])array); return; } if (arrayElemType == Converter.typeofObject) { memberNameInfo.NItransmitTypeOnMember = true; arrayElemTypeNameInfo.NItransmitTypeOnMember = true; } if (CheckTypeFormat(formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways)) { memberNameInfo.NItransmitTypeOnObject = true; arrayElemTypeNameInfo.NItransmitTypeOnObject = true; } if (arrayEnum == InternalArrayTypeE.Single) { // Single Dimensional array InternalST.Soap( this, "WriteArray ARRAY_SINGLE "); arrayNameInfo.NIname = arrayElemTypeNameInfo.NIname+"["+lengthA[0]+"]"; // BinaryFormatter array of primitive types is written out in the WriteSingleArray statement // as a byte buffer serWriter.WriteSingleArray(memberNameInfo, arrayNameInfo, arrayElemObjectInfo, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0], array); if (Converter.IsWriteAsByteArray(arrayElemTypeNameInfo.NIprimitiveTypeEnum) && (lowerBoundA[0] == 0)) { // If binaryformatter and array is of appopriate primitive type the array is // written out as a buffer of bytes. The array was transmitted in WriteSingleArray // If soap the index directly by array arrayElemTypeNameInfo.NIobjectId = 0; if (primitiveArray == null) primitiveArray = new PrimitiveArray(arrayElemTypeNameInfo.NIprimitiveTypeEnum, array); else primitiveArray.Init(arrayElemTypeNameInfo.NIprimitiveTypeEnum, array); int upperBound = upperBoundA[0]+1; for (int i = lowerBoundA[0]; i < upperBound; i++) { serWriter.WriteItemString(arrayElemTypeNameInfo, arrayElemTypeNameInfo, primitiveArray.GetValue(i)); } } else { // Non-primitive type array Object[] objectA = null; if (!arrayElemType.IsValueType) objectA = (Object[])array; int upperBound = upperBoundA[0]+1; // Soap does not write out trailing nulls. lastValue is set to the last null value. This becomes the array's upperbound // Note: value classes can't be null if (objectA != null) { int lastValue = lowerBoundA[0]-1; for (int i = lowerBoundA[0]; i< upperBound; i++) { if (objectA[i] != null) lastValue = i; } upperBound = lastValue+1; } for (int i = lowerBoundA[0]; i < upperBound; i++) { if (objectA == null) WriteArrayMember(objectInfo, arrayElemTypeNameInfo, array.GetValue(i)); else WriteArrayMember(objectInfo, arrayElemTypeNameInfo, objectA[i]); } } } else if (arrayEnum == InternalArrayTypeE.Jagged) { // Jagged Array InternalST.Soap( this, "WriteArray ARRAY_JAGGED"); int index; String arrayElemTypeDimension = null; index = arrayNameInfo.NIname.IndexOf('['); if (index < 0) throw new SerializationException(String.Format(SoapUtil.GetResourceString("Serialization_Dimensions"),arrayElemTypeNameInfo.NIname)); arrayElemTypeDimension = arrayNameInfo.NIname.Substring(index); InternalST.Soap( this, "WriteArray arrayNameInfo.NIname ",arrayNameInfo.NIname," arrayElemTypeNameInfo.NIname ",arrayElemTypeNameInfo.NIname," arrayElemTypeDimension ",arrayElemTypeDimension); arrayNameInfo.NIname = arrayElemTypeNameInfo.NIname+"["+lengthA[0]+"]"; arrayNameInfo.NIobjectId = objectId; serWriter.WriteJaggedArray(memberNameInfo, arrayNameInfo, arrayElemObjectInfo, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0]); Object[] objectA = (Object[])array; for (int i = lowerBoundA[0]; i < upperBoundA[0]+1; i++) { WriteArrayMember(objectInfo, arrayElemTypeNameInfo, objectA[i]); } } else { // Rectangle Array // Get the length for all the ranks InternalST.Soap( this, "WriteArray ARRAY_RECTANGLE"); // Express array Type using XmlData Name int index; index = arrayNameInfo.NIname.IndexOf('['); // Create length dimension string in form [3,4,2] StringBuilder sb = new StringBuilder(10); sb.Append(arrayElemTypeNameInfo.NIname); sb.Append('['); for (int i=0; i<rank; i++) { sb.Append(lengthA[i]); if (i < rank-1) sb.Append(','); } sb.Append(']'); arrayNameInfo.NIname = sb.ToString(); arrayNameInfo.NIobjectId = objectId; serWriter.WriteRectangleArray(memberNameInfo, arrayNameInfo, arrayElemObjectInfo, arrayElemTypeNameInfo, rank, lengthA, lowerBoundA); IndexTraceMessage("WriteArray Rectangle ", lengthA); bool bzero = false; for (int i=0; i<rank; i++) { if (lengthA[i] == 0) { bzero = true; break; } } if (!bzero) WriteRectangle(objectInfo, rank, lengthA, array, arrayElemTypeNameInfo, lowerBoundA); } serWriter.WriteObjectEnd(memberNameInfo, arrayNameInfo); PutNameInfo(arrayElemTypeNameInfo); PutNameInfo(arrayNameInfo); if (isAllocatedMemberNameInfo) PutNameInfo(memberNameInfo); InternalST.Soap( this, "WriteArray Exit "); }
// Initialize ParseRecord. Called when reusing. internal void Init() { // Enums PRparseTypeEnum = InternalParseTypeE.Empty; PRobjectTypeEnum = InternalObjectTypeE.Empty; PRarrayTypeEnum = InternalArrayTypeE.Empty; PRmemberTypeEnum = InternalMemberTypeE.Empty; PRmemberValueEnum = InternalMemberValueE.Empty; PRobjectPositionEnum = InternalObjectPositionE.Empty; // Object PRname = null; PRnameXmlKey = null; PRxmlNameSpace = null; PRisParsed = false; PRisProcessAttributes = false; // Value PRvalue = null; // dt attribute PRkeyDt = null; PRdtType = null; PRassemblyName = null; PRdtTypeCode = InternalPrimitiveTypeE.Invalid; PRisEnum = false; // Object ID PRobjectId = 0; // Reference ID PRidRef = 0; // Array // Array Element Type PRarrayElementTypeString = null; PRarrayElementType = null; PRisArrayVariant = false; PRarrayElementTypeCode = InternalPrimitiveTypeE.Invalid; // Array Primitive Element type PRprimitiveArrayTypeString = null; // Parsed array information PRrank = 0; PRlengthA = null; PRpositionA = null; PRlowerBoundA = null; PRupperBoundA = null; // Array map for placing array elements in array PRindexMap = null; PRmemberIndex = 0; PRlinearlength = 0; PRrectangularMap = null; PRisLowerBound = false; // SerializedStreamHeader information PRtopId = 0; PRheaderId = 0; PRisHeaderRoot = false; PRisAttributesProcessed = false; // Parsed HeaderMember Information PRisMustUnderstand = false; // Parse State PRparseStateEnum = InternalParseStateE.Initial; PRisWaitingForNestedObject = false; // ValueType Fixup needed PRisValueTypeFixup = false; PRnewObj = null; PRobjectA = null; PRprimitiveArray = null; PRobjectInfo = null; PRisRegistered = false; PRisXmlAttribute = false; }
private void WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo) { InternalArrayTypeE jagged; bool flag2; bool flag = false; if (memberNameInfo == null) { memberNameInfo = this.TypeToNameInfo(objectInfo); memberNameInfo.NIisTopLevelObject = true; flag = true; } memberNameInfo.NIisArray = true; long objectId = objectInfo.objectId; memberNameInfo.NIobjectId = objectInfo.objectId; Array array = (Array) objectInfo.obj; Type elementType = objectInfo.objectType.GetElementType(); if (Nullable.GetUnderlyingType(elementType) != null) { throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_SoapNoGenericsSupport"), new object[] { elementType })); } WriteObjectInfo info = WriteObjectInfo.Serialize(elementType, this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, (memberObjectInfo == null) ? null : memberObjectInfo.typeAttributeInfo); info.assemId = this.GetAssemblyId(info); NameInfo arrayElemTypeNameInfo = null; NameInfo arrayNameInfo = this.ArrayTypeToNameInfo(objectInfo, out arrayElemTypeNameInfo); arrayNameInfo.NIobjectId = objectId; arrayNameInfo.NIisArray = true; arrayElemTypeNameInfo.NIobjectId = objectId; arrayElemTypeNameInfo.NItransmitTypeOnMember = memberNameInfo.NItransmitTypeOnMember; arrayElemTypeNameInfo.NItransmitTypeOnObject = memberNameInfo.NItransmitTypeOnObject; arrayElemTypeNameInfo.NIisParentTypeOnObject = memberNameInfo.NIisParentTypeOnObject; int rank = array.Rank; int[] lengthA = new int[rank]; int[] lowerBoundA = new int[rank]; int[] numArray3 = new int[rank]; for (int i = 0; i < rank; i++) { lengthA[i] = array.GetLength(i); lowerBoundA[i] = array.GetLowerBound(i); numArray3[i] = array.GetUpperBound(i); } if (elementType.IsArray) { if (rank == 1) { jagged = InternalArrayTypeE.Jagged; } else { jagged = InternalArrayTypeE.Rectangular; } } else if (rank == 1) { jagged = InternalArrayTypeE.Single; } else { jagged = InternalArrayTypeE.Rectangular; } if (((elementType == Converter.typeofByte) && (rank == 1)) && (lowerBoundA[0] == 0)) { this.serWriter.WriteObjectByteArray(memberNameInfo, arrayNameInfo, info, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0], (byte[]) array); return; } if (elementType == Converter.typeofObject) { memberNameInfo.NItransmitTypeOnMember = true; arrayElemTypeNameInfo.NItransmitTypeOnMember = true; } if (this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways)) { memberNameInfo.NItransmitTypeOnObject = true; arrayElemTypeNameInfo.NItransmitTypeOnObject = true; } switch (jagged) { case InternalArrayTypeE.Single: arrayNameInfo.NIname = string.Concat(new object[] { arrayElemTypeNameInfo.NIname, "[", lengthA[0], "]" }); this.serWriter.WriteSingleArray(memberNameInfo, arrayNameInfo, info, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0], array); if (Converter.IsWriteAsByteArray(arrayElemTypeNameInfo.NIprimitiveTypeEnum) && (lowerBoundA[0] == 0)) { arrayElemTypeNameInfo.NIobjectId = 0L; if (this.primitiveArray == null) { this.primitiveArray = new PrimitiveArray(arrayElemTypeNameInfo.NIprimitiveTypeEnum, array); } else { this.primitiveArray.Init(arrayElemTypeNameInfo.NIprimitiveTypeEnum, array); } int num4 = numArray3[0] + 1; for (int j = lowerBoundA[0]; j < num4; j++) { this.serWriter.WriteItemString(arrayElemTypeNameInfo, arrayElemTypeNameInfo, this.primitiveArray.GetValue(j)); } } else { object[] objArray = null; if (!elementType.IsValueType) { objArray = (object[]) array; } int num6 = numArray3[0] + 1; if (objArray != null) { int num7 = lowerBoundA[0] - 1; for (int m = lowerBoundA[0]; m < num6; m++) { if (objArray[m] != null) { num7 = m; } } num6 = num7 + 1; } for (int k = lowerBoundA[0]; k < num6; k++) { if (objArray == null) { this.WriteArrayMember(objectInfo, arrayElemTypeNameInfo, array.GetValue(k)); } else { this.WriteArrayMember(objectInfo, arrayElemTypeNameInfo, objArray[k]); } } } goto Label_053D; case InternalArrayTypeE.Jagged: { int index = arrayNameInfo.NIname.IndexOf('['); if (index < 0) { throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_Dimensions"), new object[] { arrayElemTypeNameInfo.NIname })); } arrayNameInfo.NIname.Substring(index); arrayNameInfo.NIname = string.Concat(new object[] { arrayElemTypeNameInfo.NIname, "[", lengthA[0], "]" }); arrayNameInfo.NIobjectId = objectId; this.serWriter.WriteJaggedArray(memberNameInfo, arrayNameInfo, info, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0]); object[] objArray2 = (object[]) array; for (int n = lowerBoundA[0]; n < (numArray3[0] + 1); n++) { this.WriteArrayMember(objectInfo, arrayElemTypeNameInfo, objArray2[n]); } goto Label_053D; } default: { arrayNameInfo.NIname.IndexOf('['); StringBuilder builder = new StringBuilder(10); builder.Append(arrayElemTypeNameInfo.NIname); builder.Append('['); for (int num12 = 0; num12 < rank; num12++) { builder.Append(lengthA[num12]); if (num12 < (rank - 1)) { builder.Append(','); } } builder.Append(']'); arrayNameInfo.NIname = builder.ToString(); arrayNameInfo.NIobjectId = objectId; this.serWriter.WriteRectangleArray(memberNameInfo, arrayNameInfo, info, arrayElemTypeNameInfo, rank, lengthA, lowerBoundA); flag2 = false; for (int num13 = 0; num13 < rank; num13++) { if (lengthA[num13] == 0) { flag2 = true; break; } } break; } } if (!flag2) { this.WriteRectangle(objectInfo, rank, lengthA, array, arrayElemTypeNameInfo, lowerBoundA); } Label_053D: this.serWriter.WriteObjectEnd(memberNameInfo, arrayNameInfo); this.PutNameInfo(arrayElemTypeNameInfo); this.PutNameInfo(arrayNameInfo); if (flag) { this.PutNameInfo(memberNameInfo); } }