//internal BinaryCrossAppDomainMap crossAppDomainMap;

        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, String[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            InternalWriteItemNull();
            int assemId;

#if _DEBUG
            nameInfo.Dump("WriteObject nameInfo");
            typeNameInfo.Dump("WriteObject typeNameInfo");
#endif

            int objectId = (int)nameInfo.NIobjectId;

            //if (objectId < 0)
            //  objectId = --m_nestedObjectCount;

            if (objectId > 0)
            {
                BCLDebug.Trace("BINARY", "-----Top Level Object-----");
            }

            String objectName = null;
            if (objectId < 0)
            {
                // Nested Object
                objectName = typeNameInfo.NIname;
            }
            else
            {
                // Non-Nested
                objectName = nameInfo.NIname;
            }
            SerTrace.Log(this, "WriteObject objectName ", objectName);

            if (objectMapTable == null)
            {
                objectMapTable = new Hashtable();
            }

            ObjectMapInfo objectMapInfo = (ObjectMapInfo)objectMapTable[objectName];

            if (objectMapInfo != null && objectMapInfo.isCompatible(numMembers, memberNames, memberTypes))
            {
                // Object
                if (binaryObject == null)
                {
                    binaryObject = new BinaryObject();
                }
                binaryObject.Set(objectId, objectMapInfo.objectId);
#if _DEBUG
                binaryObject.Dump();
#endif
                binaryObject.Write(this);
            }
            else if (!typeNameInfo.NItransmitTypeOnObject)
            {
                // ObjectWithMap
                if (binaryObjectWithMap == null)
                {
                    binaryObjectWithMap = new BinaryObjectWithMap();
                }

                // BCL types are not placed into table
                assemId = (int)typeNameInfo.NIassemId;
                binaryObjectWithMap.Set(objectId, objectName, numMembers, memberNames, assemId);

                binaryObjectWithMap.Dump();
                binaryObjectWithMap.Write(this);
                if (objectMapInfo == null)
                {
                    objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
            else
            {
                // ObjectWithMapTyped
                BinaryTypeEnum[] binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                Object[]         typeInformationA = new Object[numMembers];
                int[]            assemIdA         = new int[numMembers];
                for (int i = 0; i < numMembers; i++)
                {
                    Object typeInformation = null;

                    binaryTypeEnumA[i]  = BinaryConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, objectWriter, out typeInformation, out assemId);
                    typeInformationA[i] = typeInformation;
                    assemIdA[i]         = assemId;
                    SerTrace.Log(this, "WriteObject ObjectWithMapTyped memberNames "
                                 , memberNames[i], ", memberType ", memberTypes[i], " binaryTypeEnum ", ((Enum)binaryTypeEnumA[i]).ToString()
                                 , ", typeInformation ", typeInformationA[i], " assemId ", assemIdA[i]);
                }

                if (binaryObjectWithMapTyped == null)
                {
                    binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
                }

                // BCL types are not placed in table
                assemId = (int)typeNameInfo.NIassemId;
                binaryObjectWithMapTyped.Set(objectId, objectName, numMembers, memberNames, binaryTypeEnumA, typeInformationA, assemIdA, assemId);
#if _DEBUG
                binaryObjectWithMapTyped.Dump();
#endif
                binaryObjectWithMapTyped.Write(this);
                if (objectMapInfo == null)
                {
                    objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
        }
        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            this.InternalWriteItemNull();
            int    objectId = (int)nameInfo.NIobjectId;
            string name     = objectId >= 0 ? nameInfo.NIname : typeNameInfo.NIname;

            if (this.objectMapTable == null)
            {
                this.objectMapTable = new Hashtable();
            }
            ObjectMapInfo objectMapInfo = (ObjectMapInfo)this.objectMapTable[(object)name];

            if (objectMapInfo != null && objectMapInfo.isCompatible(numMembers, memberNames, memberTypes))
            {
                if (this.binaryObject == null)
                {
                    this.binaryObject = new BinaryObject();
                }
                this.binaryObject.Set(objectId, objectMapInfo.objectId);
                this.binaryObject.Write(this);
            }
            else if (!typeNameInfo.NItransmitTypeOnObject)
            {
                if (this.binaryObjectWithMap == null)
                {
                    this.binaryObjectWithMap = new BinaryObjectWithMap();
                }
                int assemId = (int)typeNameInfo.NIassemId;
                this.binaryObjectWithMap.Set(objectId, name, numMembers, memberNames, assemId);
                this.binaryObjectWithMap.Dump();
                this.binaryObjectWithMap.Write(this);
                if (objectMapInfo != null)
                {
                    return;
                }
                this.objectMapTable.Add((object)name, (object)new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
            }
            else
            {
                BinaryTypeEnum[] binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                object[]         typeInformationA = new object[numMembers];
                int[]            memberAssemIds   = new int[numMembers];
                int assemId;
                for (int index = 0; index < numMembers; ++index)
                {
                    object typeInformation = (object)null;
                    binaryTypeEnumA[index]  = BinaryConverter.GetBinaryTypeInfo(memberTypes[index], memberObjectInfos[index], (string)null, this.objectWriter, out typeInformation, out assemId);
                    typeInformationA[index] = typeInformation;
                    memberAssemIds[index]   = assemId;
                }
                if (this.binaryObjectWithMapTyped == null)
                {
                    this.binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
                }
                assemId = (int)typeNameInfo.NIassemId;
                this.binaryObjectWithMapTyped.Set(objectId, name, numMembers, memberNames, binaryTypeEnumA, typeInformationA, memberAssemIds, assemId);
                this.binaryObjectWithMapTyped.Write(this);
                if (objectMapInfo != null)
                {
                    return;
                }
                this.objectMapTable.Add((object)name, (object)new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
            }
        }
        private void ReadArray(BinaryHeaderEnum binaryHeaderEnum)
        {
            BinaryAssemblyInfo assemblyInfo = null;

            SerTrace.Log(this, "ReadArray ");
            BinaryArray record = new BinaryArray(binaryHeaderEnum);

            record.Read(this);
            record.Dump();

            SerTrace.Log(this, "Read 1 ", ((Enum)binaryHeaderEnum).ToString());

            if (record.binaryTypeEnum == BinaryTypeEnum.ObjectUser)
            {
                if (record.assemId < 1)
                {
                    throw new SerializationException(String.Format(Environment.GetResourceString("Serialization_AssemblyId"), record.typeInformation));
                }

                assemblyInfo = (BinaryAssemblyInfo)AssemIdToAssemblyTable[record.assemId];
                SerTrace.Log(this, "ReadArray  lookup assemIdToAssembly assemId ", record.assemId, " assembly ", assemblyInfo.assemblyString);
            }
            else
            {
                assemblyInfo = SystemAssemblyInfo;                 //Urt assembly
            }
            ObjectProgress op = GetOp();
            ParseRecord    pr = op.pr;

            op.objectTypeEnum  = InternalObjectTypeE.Array;
            op.binaryTypeEnum  = record.binaryTypeEnum;
            op.typeInformation = record.typeInformation;

            ObjectProgress objectOp = (ObjectProgress)stack.PeekPeek();

            if ((objectOp == null) || (record.objectId > 0))
            {
                // Non-Nested Object
                op.name            = "System.Array";
                pr.PRparseTypeEnum = InternalParseTypeE.Object;
                op.memberValueEnum = InternalMemberValueE.Empty;
            }
            else
            {
                // Nested Object
                pr.PRparseTypeEnum   = InternalParseTypeE.Member;
                pr.PRmemberValueEnum = InternalMemberValueE.Nested;
                op.memberValueEnum   = InternalMemberValueE.Nested;

                switch (objectOp.objectTypeEnum)
                {
                case InternalObjectTypeE.Object:
                    pr.PRname           = objectOp.name;
                    pr.PRmemberTypeEnum = InternalMemberTypeE.Field;
                    op.memberTypeEnum   = InternalMemberTypeE.Field;
                    pr.PRkeyDt          = objectOp.name;
                    pr.PRdtType         = objectOp.dtType;
                    break;

                case InternalObjectTypeE.Array:
                    pr.PRmemberTypeEnum = InternalMemberTypeE.Item;
                    op.memberTypeEnum   = InternalMemberTypeE.Item;
                    break;

                default:
                    throw new SerializationException(String.Format(Environment.GetResourceString("Serialization_ObjectTypeEnum"), ((Enum)objectOp.objectTypeEnum).ToString()));
                }
            }


            pr.PRobjectId = objectReader.GetId((long)record.objectId);
            if (pr.PRobjectId == topId)
            {
                pr.PRobjectPositionEnum = InternalObjectPositionE.Top;
            }
            else if ((headerId > 0) && (pr.PRobjectId == headerId))
            {
                pr.PRobjectPositionEnum = InternalObjectPositionE.Headers;                 // Headers are an array of header objects
            }
            else
            {
                pr.PRobjectPositionEnum = InternalObjectPositionE.Child;
            }

            pr.PRobjectTypeEnum = InternalObjectTypeE.Array;

            BinaryConverter.TypeFromInfo(record.binaryTypeEnum, record.typeInformation, objectReader, assemblyInfo,
                                         out pr.PRarrayElementTypeCode, out pr.PRarrayElementTypeString,
                                         out pr.PRarrayElementType, out pr.PRisArrayVariant);

            pr.PRdtTypeCode = InternalPrimitiveTypeE.Invalid;


            pr.PRrank        = record.rank;
            pr.PRlengthA     = record.lengthA;
            pr.PRlowerBoundA = record.lowerBoundA;
            bool isPrimitiveArray = false;

            switch (record.binaryArrayTypeEnum)
            {
            case BinaryArrayTypeEnum.Single:
            case BinaryArrayTypeEnum.SingleOffset:
                op.numItems        = record.lengthA[0];
                pr.PRarrayTypeEnum = InternalArrayTypeE.Single;
                if (Converter.IsWriteAsByteArray(pr.PRarrayElementTypeCode) &&
                    (record.lowerBoundA[0] == 0))
                {
                    isPrimitiveArray = true;
                    ReadArrayAsBytes(pr);
                }
                break;

            case BinaryArrayTypeEnum.Jagged:
            case BinaryArrayTypeEnum.JaggedOffset:
                op.numItems        = record.lengthA[0];
                pr.PRarrayTypeEnum = InternalArrayTypeE.Jagged;
                break;

            case BinaryArrayTypeEnum.Rectangular:
            case BinaryArrayTypeEnum.RectangularOffset:
                int arrayLength = 1;
                for (int i = 0; i < record.rank; i++)
                {
                    arrayLength = arrayLength * record.lengthA[i];
                }
                op.numItems        = arrayLength;
                pr.PRarrayTypeEnum = InternalArrayTypeE.Rectangular;
                break;

            default:
                throw new SerializationException(String.Format(Environment.GetResourceString("Serialization_ArrayType"), ((Enum)record.binaryArrayTypeEnum).ToString()));
            }

            if (!isPrimitiveArray)
            {
                stack.Push(op);
            }
            else
            {
                PutOp(op);
            }

            SerTrace.Log(this, "ReadArray ", ((Enum)record.binaryArrayTypeEnum).ToString(), " length ", op.numItems);
            objectReader.Parse(pr);

            if (isPrimitiveArray)
            {
                pr.PRparseTypeEnum = InternalParseTypeE.ObjectEnd;
                objectReader.Parse(pr);
            }
        }
        private void ReadArray(BinaryHeaderEnum binaryHeaderEnum)
        {
            BinaryAssemblyInfo assemblyInfo = null;
            BinaryArray        array        = new BinaryArray(binaryHeaderEnum);

            array.Read(this);
            if (array.binaryTypeEnum == BinaryTypeEnum.ObjectUser)
            {
                if (array.assemId < 1)
                {
                    throw new SerializationException(Environment.GetResourceString("Serialization_AssemblyId", new object[] { array.typeInformation }));
                }
                assemblyInfo = (BinaryAssemblyInfo)this.AssemIdToAssemblyTable[array.assemId];
            }
            else
            {
                assemblyInfo = this.SystemAssemblyInfo;
            }
            ObjectProgress op = this.GetOp();
            ParseRecord    pr = op.pr;

            op.objectTypeEnum  = InternalObjectTypeE.Array;
            op.binaryTypeEnum  = array.binaryTypeEnum;
            op.typeInformation = array.typeInformation;
            ObjectProgress progress2 = (ObjectProgress)this.stack.PeekPeek();

            if ((progress2 == null) || (array.objectId > 0))
            {
                op.name            = "System.Array";
                pr.PRparseTypeEnum = InternalParseTypeE.Object;
                op.memberValueEnum = InternalMemberValueE.Empty;
            }
            else
            {
                pr.PRparseTypeEnum   = InternalParseTypeE.Member;
                pr.PRmemberValueEnum = InternalMemberValueE.Nested;
                op.memberValueEnum   = InternalMemberValueE.Nested;
                switch (progress2.objectTypeEnum)
                {
                case InternalObjectTypeE.Object:
                    pr.PRname           = progress2.name;
                    pr.PRmemberTypeEnum = InternalMemberTypeE.Field;
                    op.memberTypeEnum   = InternalMemberTypeE.Field;
                    pr.PRkeyDt          = progress2.name;
                    pr.PRdtType         = progress2.dtType;
                    goto Label_0177;

                case InternalObjectTypeE.Array:
                    pr.PRmemberTypeEnum = InternalMemberTypeE.Item;
                    op.memberTypeEnum   = InternalMemberTypeE.Item;
                    goto Label_0177;
                }
                throw new SerializationException(Environment.GetResourceString("Serialization_ObjectTypeEnum", new object[] { progress2.objectTypeEnum.ToString() }));
            }
Label_0177:
            pr.PRobjectId = this.objectReader.GetId((long)array.objectId);
            if (pr.PRobjectId == this.topId)
            {
                pr.PRobjectPositionEnum = InternalObjectPositionE.Top;
            }
            else if ((this.headerId > 0L) && (pr.PRobjectId == this.headerId))
            {
                pr.PRobjectPositionEnum = InternalObjectPositionE.Headers;
            }
            else
            {
                pr.PRobjectPositionEnum = InternalObjectPositionE.Child;
            }
            pr.PRobjectTypeEnum = InternalObjectTypeE.Array;
            BinaryConverter.TypeFromInfo(array.binaryTypeEnum, array.typeInformation, this.objectReader, assemblyInfo, out pr.PRarrayElementTypeCode, out pr.PRarrayElementTypeString, out pr.PRarrayElementType, out pr.PRisArrayVariant);
            pr.PRdtTypeCode  = InternalPrimitiveTypeE.Invalid;
            pr.PRrank        = array.rank;
            pr.PRlengthA     = array.lengthA;
            pr.PRlowerBoundA = array.lowerBoundA;
            bool flag = false;

            switch (array.binaryArrayTypeEnum)
            {
            case BinaryArrayTypeEnum.Single:
            case BinaryArrayTypeEnum.SingleOffset:
                op.numItems        = array.lengthA[0];
                pr.PRarrayTypeEnum = InternalArrayTypeE.Single;
                if (Converter.IsWriteAsByteArray(pr.PRarrayElementTypeCode) && (array.lowerBoundA[0] == 0))
                {
                    flag = true;
                    this.ReadArrayAsBytes(pr);
                }
                break;

            case BinaryArrayTypeEnum.Jagged:
            case BinaryArrayTypeEnum.JaggedOffset:
                op.numItems        = array.lengthA[0];
                pr.PRarrayTypeEnum = InternalArrayTypeE.Jagged;
                break;

            case BinaryArrayTypeEnum.Rectangular:
            case BinaryArrayTypeEnum.RectangularOffset:
            {
                int num = 1;
                for (int i = 0; i < array.rank; i++)
                {
                    num *= array.lengthA[i];
                }
                op.numItems        = num;
                pr.PRarrayTypeEnum = InternalArrayTypeE.Rectangular;
                break;
            }

            default:
                throw new SerializationException(Environment.GetResourceString("Serialization_ArrayType", new object[] { array.binaryArrayTypeEnum.ToString() }));
            }
            if (!flag)
            {
                this.stack.Push(op);
            }
            else
            {
                this.PutOp(op);
            }
            this.objectReader.Parse(pr);
            if (flag)
            {
                pr.PRparseTypeEnum = InternalParseTypeE.ObjectEnd;
                this.objectReader.Parse(pr);
            }
        }
Beispiel #5
0
        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            this.InternalWriteItemNull();
            int    nIobjectId = (int)nameInfo.NIobjectId;
            string name       = null;

            if (nIobjectId < 0)
            {
                name = typeNameInfo.NIname;
            }
            else
            {
                name = nameInfo.NIname;
            }
            if (this.objectMapTable == null)
            {
                this.objectMapTable = new Hashtable();
            }
            ObjectMapInfo info = (ObjectMapInfo)this.objectMapTable[name];

            if ((info != null) && info.isCompatible(numMembers, memberNames, memberTypes))
            {
                if (this.binaryObject == null)
                {
                    this.binaryObject = new BinaryObject();
                }
                this.binaryObject.Set(nIobjectId, info.objectId);
                this.binaryObject.Write(this);
            }
            else
            {
                int nIassemId;
                if (!typeNameInfo.NItransmitTypeOnObject)
                {
                    if (this.binaryObjectWithMap == null)
                    {
                        this.binaryObjectWithMap = new BinaryObjectWithMap();
                    }
                    nIassemId = (int)typeNameInfo.NIassemId;
                    this.binaryObjectWithMap.Set(nIobjectId, name, numMembers, memberNames, nIassemId);
                    this.binaryObjectWithMap.Dump();
                    this.binaryObjectWithMap.Write(this);
                    if (info == null)
                    {
                        this.objectMapTable.Add(name, new ObjectMapInfo(nIobjectId, numMembers, memberNames, memberTypes));
                    }
                }
                else
                {
                    BinaryTypeEnum[] binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                    object[]         typeInformationA = new object[numMembers];
                    int[]            memberAssemIds   = new int[numMembers];
                    for (int i = 0; i < numMembers; i++)
                    {
                        object typeInformation = null;
                        binaryTypeEnumA[i]  = BinaryConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, this.objectWriter, out typeInformation, out nIassemId);
                        typeInformationA[i] = typeInformation;
                        memberAssemIds[i]   = nIassemId;
                    }
                    if (this.binaryObjectWithMapTyped == null)
                    {
                        this.binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
                    }
                    nIassemId = (int)typeNameInfo.NIassemId;
                    this.binaryObjectWithMapTyped.Set(nIobjectId, name, numMembers, memberNames, binaryTypeEnumA, typeInformationA, memberAssemIds, nIassemId);
                    this.binaryObjectWithMapTyped.Write(this);
                    if (info == null)
                    {
                        this.objectMapTable.Add(name, new ObjectMapInfo(nIobjectId, numMembers, memberNames, memberTypes));
                    }
                }
            }
        }