private bool CheckForNull(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, object data)
 {
     bool flag = false;
     if (data == null)
     {
         flag = true;
     }
     if (flag && ((((this.formatterEnums.FEserializerTypeEnum == InternalSerializerTypeE.Binary) || memberNameInfo.NIisArrayItem) || (memberNameInfo.NItransmitTypeOnObject || memberNameInfo.NItransmitTypeOnMember)) || (objectInfo.isSi || this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways))))
     {
         if (typeNameInfo.NIisArrayItem)
         {
             if (typeNameInfo.NIarrayEnum == InternalArrayTypeE.Single)
             {
                 this.serWriter.WriteDelayedNullItem();
                 return flag;
             }
             this.serWriter.WriteNullItem(memberNameInfo, typeNameInfo);
             return flag;
         }
         this.serWriter.WriteNullMember(memberNameInfo, typeNameInfo);
     }
     return flag;
 }
Example #2
0
 // Token: 0x06005384 RID: 21380 RVA: 0x0012793E File Offset: 0x00125B3E
 private NameInfo TypeToNameInfo(WriteObjectInfo objectInfo, NameInfo nameInfo)
 {
     return(this.TypeToNameInfo(objectInfo.objectType, objectInfo, this.ToCode(objectInfo.objectType), nameInfo));
 }
        [System.Security.SecurityCritical]  // auto-generated
        private void WriteMembers(NameInfo memberNameInfo,
                                  NameInfo memberTypeNameInfo,
                                  Object   memberData,
                                  WriteObjectInfo objectInfo,
                                  NameInfo typeNameInfo,
                                  WriteObjectInfo memberObjectInfo
                                 )
        {
            SerTrace.Log( this, "WriteMembers Entry memberType: ",memberTypeNameInfo.NIname," memberName: ",memberNameInfo.NIname," data: ",memberData," objectId: ",objectInfo.objectId, " Container object ",objectInfo.obj, " memberObjectinfo ",memberObjectInfo);
            Type memberType = memberNameInfo.NItype;
            bool assignUniqueIdToValueType = false;

            // Types are transmitted for a member as follows:
            // The member is of type object
            // The member object of type is ISerializable and
            //  Binary - Types always transmitted.

            if (Object.ReferenceEquals(memberType, Converter.typeofObject) || (object)Nullable.GetUnderlyingType(memberType) != null)
            {
                memberTypeNameInfo.NItransmitTypeOnMember  = true;
                memberNameInfo.NItransmitTypeOnMember  = true;              
            }

            if (CheckTypeFormat(formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways) || (objectInfo.isSi) )
            {
                memberTypeNameInfo.NItransmitTypeOnObject  = true;
                memberNameInfo.NItransmitTypeOnObject  = true;
                memberNameInfo.NIisParentTypeOnObject = true;
            }

            if (CheckForNull(objectInfo, memberNameInfo, memberTypeNameInfo, memberData))
            {
                return;
            }

            Object outObj = memberData;
            Type outType = null;

            // If member type does not equal data type, transmit type on object.
            if (memberTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Invalid)
            {
                outType = GetType(outObj);
                if (!Object.ReferenceEquals(memberType, outType))
                {
                    memberTypeNameInfo.NItransmitTypeOnMember  = true;
                    memberNameInfo.NItransmitTypeOnMember  = true;    
                }
            }

            if (Object.ReferenceEquals(memberType, Converter.typeofObject))
            {
                assignUniqueIdToValueType = true;
                memberType = GetType(memberData);
                if (memberObjectInfo == null)
                    TypeToNameInfo(memberType, memberTypeNameInfo);
                else
                    TypeToNameInfo(memberObjectInfo, memberTypeNameInfo);                   
                SerTrace.Log( this, "WriteMembers memberType Object, actual memberType ",memberType);                                                                               
            }

            if (memberObjectInfo != null && memberObjectInfo.isArray)
            {
                // Array
                SerTrace.Log( this, "WriteMembers IsArray");

                long arrayId = 0;
                if ((object)outType == null)
                    outType = GetType(outObj);
                // outObj is an array. It can never be a value type..
                arrayId = Schedule(outObj, false, null, memberObjectInfo);
                if (arrayId > 0)
                {
                    // Array as object
                    SerTrace.Log( this, "WriteMembers Schedule 3");
                    memberNameInfo.NIobjectId = arrayId;
                    WriteObjectRef(memberNameInfo, arrayId); 
                }
                else
                {
                    // Nested Array
                    serWriter.WriteMemberNested(memberNameInfo);

                    memberObjectInfo.objectId = arrayId;
                    memberNameInfo.NIobjectId = arrayId;
                    WriteArray(memberObjectInfo, memberNameInfo, memberObjectInfo);
                    objectInfo.ObjectEnd();

                }
                SerTrace.Log( this, "WriteMembers Array Exit ");
                return;
            }

            if (!WriteKnownValueClass(memberNameInfo, memberTypeNameInfo, memberData))
            {
                SerTrace.Log( this, "WriteMembers Object ",memberData);

#if false
                // Value or NO_ID, need to explicitly check for IsValue because a top level
                // value class has an objectId of 1
                /*
                if (memberType.IsValueType)
                {
                    SerTrace.Log( this, "WriteMembers Value Type or NO_ID parameter");

                    bool isNew;
                    memberObjectInfo.objectId = InternalGetId(outObj, assignUniqueIdToValueType, memberType, out isNew) ;
                    NameInfo newTypeNameInfo = TypeToNameInfo(memberObjectInfo);
                    newTypeNameInfo.NIobjectId = memberObjectInfo.objectId;
                    Write( memberObjectInfo, memberNameInfo, newTypeNameInfo);
                    PutNameInfo(newTypeNameInfo);
                    memberObjectInfo.ObjectEnd();
                }
                else
                */
#endif
                {
                    SerTrace.Log( this, "WriteMembers Schedule 4 ", outType, " memberInfo ",memberObjectInfo);
                    if ((object)outType == null)
                        outType = GetType(outObj);
                    long memberObjectId = Schedule(outObj, assignUniqueIdToValueType, outType, memberObjectInfo);
                    if (memberObjectId < 0)
                    {
                        // Nested object
                        SerTrace.Log( this, "WriteMembers Nesting");

                        memberObjectInfo.objectId = memberObjectId;
                        NameInfo newTypeNameInfo = TypeToNameInfo(memberObjectInfo);
                        newTypeNameInfo.NIobjectId = memberObjectId;
                        Write(memberObjectInfo, memberNameInfo, newTypeNameInfo);
                        PutNameInfo(newTypeNameInfo);
                        memberObjectInfo.ObjectEnd();
                    }
                    else
                    {
                        // Object reference
                        memberNameInfo.NIobjectId = memberObjectId;
                        WriteObjectRef(memberNameInfo, memberObjectId); 
                    }
                }
            }

            SerTrace.Log( this, "WriteMembers Exit ");
        }
 private void PutNameInfo(NameInfo nameInfo)
 {
     niPool.Push(nameInfo);
 }
        // Transforms a type to the serialized string form. URT Primitive types are converted to XMLData Types
        private NameInfo TypeToNameInfo(Type type, WriteObjectInfo objectInfo, InternalPrimitiveTypeE code, NameInfo nameInfo)
        {
            SerTrace.Log( this, "TypeToNameInfo Entry type ",type,", objectInfo ",objectInfo,", code ", ((Enum)code).ToString());
            if (nameInfo == null)
                nameInfo = GetNameInfo();
            else
                nameInfo.Init();

            if (code == InternalPrimitiveTypeE.Invalid)
            {
                if (objectInfo != null)
                {
                    nameInfo.NIname = objectInfo.GetTypeFullName();
                    nameInfo.NIassemId = objectInfo.assemId;                    
                }
            }
            nameInfo.NIprimitiveTypeEnum = code; 
            nameInfo.NItype = type;

            SerTrace.Log( this, "TypeToNameInfo Exit ",type, " typeName "+nameInfo.NIname);
            return nameInfo;            
        }
        // Determines if a type is a primitive type, if it is it is written

        private bool WriteKnownValueClass(NameInfo memberNameInfo, NameInfo typeNameInfo, Object data) 
        {
#if _DEBUG                        
            SerTrace.Log( this, "WriteKnownValueClass Entry ",typeNameInfo.NIname," ",data," ",memberNameInfo.NIname);
            memberNameInfo.Dump("WriteKnownValueClass memberNameInfo");         
            typeNameInfo.Dump("WriteKnownValueClass typeNameInfo");
#endif            

            if (Object.ReferenceEquals(typeNameInfo.NItype, Converter.typeofString))
            {
                WriteString(memberNameInfo, typeNameInfo, data);
            }
            else
            {
                if (typeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Invalid)
                {
                    SerTrace.Log( this, "WriteKnownValueClass Exit false");                     
                    return false;
                }
                else
                {
                    if (typeNameInfo.NIisArray) // null if an array
                        serWriter.WriteItem(memberNameInfo, typeNameInfo, data);
                    else
                    {
                        serWriter.WriteMember(memberNameInfo, typeNameInfo, data);
                    }
                }
            }

            SerTrace.Log( this, "WriteKnownValueClass Exit true");
            return true;
        }
 internal void WriteMemberString(NameInfo memberNameInfo, NameInfo typeNameInfo, String value)
 { 
     InternalWriteItemNull();
     if (memberNameInfo.NIisArrayItem) 
     { 
         BCLDebug.Trace("BINARY", "-----item-----");
     } 
     else
     {
         BCLDebug.Trace("BINARY", "-----",memberNameInfo.NIname,"-----");
     } 
     WriteObjectString((int)typeNameInfo.NIobjectId, value);
 } 
        internal void WriteMember(NameInfo memberNameInfo, NameInfo typeNameInfo, Object value)
        { 
#if _DEBUG
            SerTrace.Log("BinaryWriter", "Write Member memberName ",memberNameInfo.NIname,", value ",value);
            memberNameInfo.Dump("WriteMember memberNameInfo");
            typeNameInfo.Dump("WriteMember typeNameInfo"); 
#endif
            InternalWriteItemNull(); 
            InternalPrimitiveTypeE typeInformation = typeNameInfo.NIprimitiveTypeEnum; 

            // Writes Members with primitive values 

            if (memberNameInfo.NItransmitTypeOnMember)
            {
                if (memberPrimitiveTyped == null) 
                    memberPrimitiveTyped = new MemberPrimitiveTyped();
                memberPrimitiveTyped.Set((InternalPrimitiveTypeE)typeInformation, value); 
 
                if (memberNameInfo.NIisArrayItem)
                { 
                    BCLDebug.Trace("BINARY",  "-----item-----");
                }
                else
                { 
                    BCLDebug.Trace("BINARY","-----",memberNameInfo.NIname,"-----");
                } 
                memberPrimitiveTyped.Dump(); 

                memberPrimitiveTyped.Write(this); 
            }
            else
            {
                if (memberPrimitiveUnTyped == null) 
                    memberPrimitiveUnTyped = new MemberPrimitiveUnTyped();
                memberPrimitiveUnTyped.Set(typeInformation, value); 
 
                if (memberNameInfo.NIisArrayItem)
                { 
                    BCLDebug.Trace("BINARY", "-----item-----");
                }
                else
                { 
                    BCLDebug.Trace("BINARY", "-----",memberNameInfo.NIname,"-----");
                } 
                memberPrimitiveUnTyped.Dump(); 

                memberPrimitiveUnTyped.Write(this); 

            }
        }
Example #9
0
        private void WriteRectangle(WriteObjectInfo objectInfo, int rank, int[] maxA, Array array, NameInfo arrayElemNameTypeInfo, int[] lowerBoundA)
        {
            int[] array2 = new int[rank];
            int[] array3 = null;
            bool  flag   = false;

            if (lowerBoundA != null)
            {
                for (int i = 0; i < rank; i++)
                {
                    if (lowerBoundA[i] != 0)
                    {
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                array3 = new int[rank];
            }
            bool flag2 = true;

            while (flag2)
            {
                flag2 = false;
                if (flag)
                {
                    for (int j = 0; j < rank; j++)
                    {
                        array3[j] = array2[j] + lowerBoundA[j];
                    }
                    this.WriteArrayMember(objectInfo, arrayElemNameTypeInfo, array.GetValue(array3));
                }
                else
                {
                    this.WriteArrayMember(objectInfo, arrayElemNameTypeInfo, array.GetValue(array2));
                }
                for (int k = rank - 1; k > -1; k--)
                {
                    if (array2[k] < maxA[k] - 1)
                    {
                        array2[k]++;
                        if (k < rank - 1)
                        {
                            for (int l = k + 1; l < rank; l++)
                            {
                                array2[l] = 0;
                            }
                        }
                        flag2 = true;
                        break;
                    }
                }
            }
        }
Example #10
0
        private void WriteArrayMember(WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, object data)
        {
            arrayElemTypeNameInfo.NIisArrayItem = true;
            if (this.CheckForNull(objectInfo, arrayElemTypeNameInfo, arrayElemTypeNameInfo, data))
            {
                return;
            }
            Type type = null;
            bool flag = false;

            if (arrayElemTypeNameInfo.NItransmitTypeOnMember)
            {
                flag = true;
            }
            if (!flag && !arrayElemTypeNameInfo.IsSealed)
            {
                type = this.GetType(data);
                if (arrayElemTypeNameInfo.NItype != type)
                {
                    flag = true;
                }
            }
            NameInfo nameInfo;

            if (flag)
            {
                if (type == null)
                {
                    type = this.GetType(data);
                }
                nameInfo = this.TypeToNameInfo(type);
                nameInfo.NItransmitTypeOnMember = true;
                nameInfo.NIobjectId             = arrayElemTypeNameInfo.NIobjectId;
                nameInfo.NIassemId     = arrayElemTypeNameInfo.NIassemId;
                nameInfo.NIisArrayItem = true;
            }
            else
            {
                nameInfo = arrayElemTypeNameInfo;
                nameInfo.NIisArrayItem = true;
            }
            if (!this.WriteKnownValueClass(arrayElemTypeNameInfo, nameInfo, data))
            {
                bool assignUniqueIdToValueType = false;
                if (arrayElemTypeNameInfo.NItype == Converter.typeofObject)
                {
                    assignUniqueIdToValueType = true;
                }
                long num = this.Schedule(data, assignUniqueIdToValueType, nameInfo.NItype);
                arrayElemTypeNameInfo.NIobjectId = num;
                nameInfo.NIobjectId = num;
                if (num < 1L)
                {
                    WriteObjectInfo writeObjectInfo = WriteObjectInfo.Serialize(data, this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this, this.m_binder);
                    writeObjectInfo.objectId = num;
                    if (arrayElemTypeNameInfo.NItype != Converter.typeofObject && Nullable.GetUnderlyingType(arrayElemTypeNameInfo.NItype) == null)
                    {
                        writeObjectInfo.assemId = nameInfo.NIassemId;
                    }
                    else
                    {
                        writeObjectInfo.assemId = this.GetAssemblyId(writeObjectInfo);
                    }
                    NameInfo nameInfo2 = this.TypeToNameInfo(writeObjectInfo);
                    nameInfo2.NIobjectId     = num;
                    writeObjectInfo.objectId = num;
                    this.Write(writeObjectInfo, nameInfo, nameInfo2);
                    writeObjectInfo.ObjectEnd();
                }
                else
                {
                    this.serWriter.WriteItemObjectRef(arrayElemTypeNameInfo, (int)num);
                }
            }
            if (arrayElemTypeNameInfo.NItransmitTypeOnMember)
            {
                this.PutNameInfo(nameInfo);
            }
        }
Example #11
0
        private void WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
        {
            bool flag = false;

            if (memberNameInfo == null)
            {
                memberNameInfo = this.TypeToNameInfo(objectInfo);
                flag           = true;
            }
            memberNameInfo.NIisArray = true;
            long objectId = objectInfo.objectId;

            memberNameInfo.NIobjectId = objectInfo.objectId;
            Array           array           = (Array)objectInfo.obj;
            Type            objectType      = objectInfo.objectType;
            Type            elementType     = objectType.GetElementType();
            WriteObjectInfo writeObjectInfo = null;

            if (!elementType.IsPrimitive)
            {
                writeObjectInfo         = WriteObjectInfo.Serialize(elementType, this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this.m_binder);
                writeObjectInfo.assemId = this.GetAssemblyId(writeObjectInfo);
            }
            NameInfo nameInfo;

            if (writeObjectInfo == null)
            {
                nameInfo = this.TypeToNameInfo(elementType);
            }
            else
            {
                nameInfo = this.TypeToNameInfo(writeObjectInfo);
            }
            nameInfo.NIisArray = nameInfo.NItype.IsArray;
            NameInfo nameInfo2 = memberNameInfo;

            nameInfo2.NIobjectId            = objectId;
            nameInfo2.NIisArray             = true;
            nameInfo.NIobjectId             = objectId;
            nameInfo.NItransmitTypeOnMember = memberNameInfo.NItransmitTypeOnMember;
            nameInfo.NItransmitTypeOnObject = memberNameInfo.NItransmitTypeOnObject;
            nameInfo.NIisParentTypeOnObject = memberNameInfo.NIisParentTypeOnObject;
            int rank = array.Rank;

            int[] array2 = new int[rank];
            int[] array3 = new int[rank];
            int[] array4 = new int[rank];
            for (int i = 0; i < rank; i++)
            {
                array2[i] = array.GetLength(i);
                array3[i] = array.GetLowerBound(i);
                array4[i] = array.GetUpperBound(i);
            }
            InternalArrayTypeE internalArrayTypeE;

            if (nameInfo.NIisArray)
            {
                if (rank == 1)
                {
                    internalArrayTypeE = InternalArrayTypeE.Jagged;
                }
                else
                {
                    internalArrayTypeE = InternalArrayTypeE.Rectangular;
                }
            }
            else if (rank == 1)
            {
                internalArrayTypeE = InternalArrayTypeE.Single;
            }
            else
            {
                internalArrayTypeE = InternalArrayTypeE.Rectangular;
            }
            nameInfo.NIarrayEnum = internalArrayTypeE;
            if (elementType == Converter.typeofByte && rank == 1 && array3[0] == 0)
            {
                this.serWriter.WriteObjectByteArray(memberNameInfo, nameInfo2, writeObjectInfo, nameInfo, array2[0], array3[0], (byte[])array);
                return;
            }
            if (elementType == Converter.typeofObject || Nullable.GetUnderlyingType(elementType) != null)
            {
                memberNameInfo.NItransmitTypeOnMember = true;
                nameInfo.NItransmitTypeOnMember       = true;
            }
            if (this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways))
            {
                memberNameInfo.NItransmitTypeOnObject = true;
                nameInfo.NItransmitTypeOnObject       = true;
            }
            if (internalArrayTypeE == InternalArrayTypeE.Single)
            {
                this.serWriter.WriteSingleArray(memberNameInfo, nameInfo2, writeObjectInfo, nameInfo, array2[0], array3[0], array);
                if (!Converter.IsWriteAsByteArray(nameInfo.NIprimitiveTypeEnum) || array3[0] != 0)
                {
                    object[] array5 = null;
                    if (!elementType.IsValueType)
                    {
                        array5 = (object[])array;
                    }
                    int num = array4[0] + 1;
                    for (int j = array3[0]; j < num; j++)
                    {
                        if (array5 == null)
                        {
                            this.WriteArrayMember(objectInfo, nameInfo, array.GetValue(j));
                        }
                        else
                        {
                            this.WriteArrayMember(objectInfo, nameInfo, array5[j]);
                        }
                    }
                    this.serWriter.WriteItemEnd();
                }
            }
            else if (internalArrayTypeE == InternalArrayTypeE.Jagged)
            {
                nameInfo2.NIobjectId = objectId;
                this.serWriter.WriteJaggedArray(memberNameInfo, nameInfo2, writeObjectInfo, nameInfo, array2[0], array3[0]);
                object[] array6 = (object[])array;
                for (int k = array3[0]; k < array4[0] + 1; k++)
                {
                    this.WriteArrayMember(objectInfo, nameInfo, array6[k]);
                }
                this.serWriter.WriteItemEnd();
            }
            else
            {
                nameInfo2.NIobjectId = objectId;
                this.serWriter.WriteRectangleArray(memberNameInfo, nameInfo2, writeObjectInfo, nameInfo, rank, array2, array3);
                bool flag2 = false;
                for (int l = 0; l < rank; l++)
                {
                    if (array2[l] == 0)
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    this.WriteRectangle(objectInfo, rank, array2, array, nameInfo, array3);
                }
                this.serWriter.WriteItemEnd();
            }
            this.serWriter.WriteObjectEnd(memberNameInfo, nameInfo2);
            this.PutNameInfo(nameInfo);
            if (flag)
            {
                this.PutNameInfo(memberNameInfo);
            }
        }
Example #12
0
        private void WriteMembers(NameInfo memberNameInfo, NameInfo memberTypeNameInfo, object memberData, WriteObjectInfo objectInfo, NameInfo typeNameInfo, WriteObjectInfo memberObjectInfo)
        {
            Type type = memberNameInfo.NItype;
            bool assignUniqueIdToValueType = false;

            if (type == Converter.typeofObject || Nullable.GetUnderlyingType(type) != null)
            {
                memberTypeNameInfo.NItransmitTypeOnMember = true;
                memberNameInfo.NItransmitTypeOnMember     = true;
            }
            if (this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways) || objectInfo.isSi)
            {
                memberTypeNameInfo.NItransmitTypeOnObject = true;
                memberNameInfo.NItransmitTypeOnObject     = true;
                memberNameInfo.NIisParentTypeOnObject     = true;
            }
            if (this.CheckForNull(objectInfo, memberNameInfo, memberTypeNameInfo, memberData))
            {
                return;
            }
            Type type2 = null;

            if (memberTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Invalid)
            {
                type2 = this.GetType(memberData);
                if (type != type2)
                {
                    memberTypeNameInfo.NItransmitTypeOnMember = true;
                    memberNameInfo.NItransmitTypeOnMember     = true;
                }
            }
            if (type == Converter.typeofObject)
            {
                assignUniqueIdToValueType = true;
                type = this.GetType(memberData);
                if (memberObjectInfo == null)
                {
                    this.TypeToNameInfo(type, memberTypeNameInfo);
                }
                else
                {
                    this.TypeToNameInfo(memberObjectInfo, memberTypeNameInfo);
                }
            }
            if (memberObjectInfo == null || !memberObjectInfo.isArray)
            {
                if (!this.WriteKnownValueClass(memberNameInfo, memberTypeNameInfo, memberData))
                {
                    if (type2 == null)
                    {
                        type2 = this.GetType(memberData);
                    }
                    long num = this.Schedule(memberData, assignUniqueIdToValueType, type2, memberObjectInfo);
                    if (num < 0L)
                    {
                        memberObjectInfo.objectId = num;
                        NameInfo nameInfo = this.TypeToNameInfo(memberObjectInfo);
                        nameInfo.NIobjectId = num;
                        this.Write(memberObjectInfo, memberNameInfo, nameInfo);
                        this.PutNameInfo(nameInfo);
                        memberObjectInfo.ObjectEnd();
                        return;
                    }
                    memberNameInfo.NIobjectId = num;
                    this.WriteObjectRef(memberNameInfo, num);
                }
                return;
            }
            if (type2 == null)
            {
                type2 = this.GetType(memberData);
            }
            long num2 = this.Schedule(memberData, false, null, memberObjectInfo);

            if (num2 > 0L)
            {
                memberNameInfo.NIobjectId = num2;
                this.WriteObjectRef(memberNameInfo, num2);
                return;
            }
            this.serWriter.WriteMemberNested(memberNameInfo);
            memberObjectInfo.objectId = num2;
            memberNameInfo.NIobjectId = num2;
            this.WriteArray(memberObjectInfo, memberNameInfo, memberObjectInfo);
            objectInfo.ObjectEnd();
        }
Example #13
0
        private void WriteMemberSetup(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, string memberName, Type memberType, object memberData, WriteObjectInfo memberObjectInfo)
        {
            NameInfo nameInfo = this.MemberToNameInfo(memberName);

            if (memberObjectInfo != null)
            {
                nameInfo.NIassemId = memberObjectInfo.assemId;
            }
            nameInfo.NItype = memberType;
            NameInfo nameInfo2;

            if (memberObjectInfo == null)
            {
                nameInfo2 = this.TypeToNameInfo(memberType);
            }
            else
            {
                nameInfo2 = this.TypeToNameInfo(memberObjectInfo);
            }
            nameInfo.NItransmitTypeOnObject = memberNameInfo.NItransmitTypeOnObject;
            nameInfo.NIisParentTypeOnObject = memberNameInfo.NIisParentTypeOnObject;
            this.WriteMembers(nameInfo, nameInfo2, memberData, objectInfo, typeNameInfo, memberObjectInfo);
            this.PutNameInfo(nameInfo);
            this.PutNameInfo(nameInfo2);
        }
Example #14
0
        private void Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
        {
            object obj = objectInfo.obj;

            if (obj == null)
            {
                throw new ArgumentNullException("objectInfo.obj", Environment.GetResourceString("ArgumentNull_Obj"));
            }
            Type objectType = objectInfo.objectType;
            long objectId   = objectInfo.objectId;

            if (objectType == Converter.typeofString)
            {
                memberNameInfo.NIobjectId = objectId;
                this.serWriter.WriteObjectString((int)objectId, obj.ToString());
                return;
            }
            if (objectInfo.isArray)
            {
                this.WriteArray(objectInfo, memberNameInfo, null);
                return;
            }
            string[] array;
            Type[]   array2;
            object[] array3;
            objectInfo.GetMemberInfo(out array, out array2, out array3);
            if (objectInfo.isSi || this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways))
            {
                memberNameInfo.NItransmitTypeOnObject = true;
                memberNameInfo.NIisParentTypeOnObject = true;
                typeNameInfo.NItransmitTypeOnObject   = true;
                typeNameInfo.NIisParentTypeOnObject   = true;
            }
            WriteObjectInfo[] array4 = new WriteObjectInfo[array.Length];
            for (int i = 0; i < array2.Length; i++)
            {
                Type type;
                if (array2[i] != null)
                {
                    type = array2[i];
                }
                else if (array3[i] != null)
                {
                    type = this.GetType(array3[i]);
                }
                else
                {
                    type = Converter.typeofObject;
                }
                if (this.ToCode(type) == InternalPrimitiveTypeE.Invalid && type != Converter.typeofString)
                {
                    if (array3[i] != null)
                    {
                        array4[i]         = WriteObjectInfo.Serialize(array3[i], this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this, this.m_binder);
                        array4[i].assemId = this.GetAssemblyId(array4[i]);
                    }
                    else
                    {
                        array4[i]         = WriteObjectInfo.Serialize(array2[i], this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this.m_binder);
                        array4[i].assemId = this.GetAssemblyId(array4[i]);
                    }
                }
            }
            this.Write(objectInfo, memberNameInfo, typeNameInfo, array, array2, array3, array4);
        }
Example #15
0
 // Token: 0x06005385 RID: 21381 RVA: 0x0012795A File Offset: 0x00125B5A
 private void TypeToNameInfo(Type type, NameInfo nameInfo)
 {
     this.TypeToNameInfo(type, null, this.ToCode(type), nameInfo);
 }
        [System.Security.SecurityCritical]  // auto-generated
        internal void WriteSingleArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound, Array array) 
        { 
            InternalWriteItemNull();
#if _DEBUG 
            arrayNameInfo.Dump("WriteSingleArray arrayNameInfo");
            arrayElemTypeNameInfo.Dump("WriteSingleArray arrayElemTypeNameInfo");
#endif
            BinaryArrayTypeEnum binaryArrayTypeEnum; 
            Int32[] lengthA = new Int32[1];
            lengthA[0] = length; 
            Int32[] lowerBoundA = null; 
            Object typeInformation = null;
 
            if (lowerBound == 0)
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
            } 
            else
            { 
                binaryArrayTypeEnum = BinaryArrayTypeEnum.SingleOffset; 
                lowerBoundA = new Int32[1];
                lowerBoundA[0] = lowerBound; 
            }

            int assemId;
 
            BinaryTypeEnum binaryTypeEnum = BinaryConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo.NItype, objectInfo, arrayElemTypeNameInfo.NIname, objectWriter, out typeInformation, out assemId);
 
            if (binaryArray == null) 
                binaryArray = new BinaryArray();
            binaryArray.Set((int)arrayNameInfo.NIobjectId, (int)1, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, binaryArrayTypeEnum, assemId); 

            if (arrayNameInfo.NIobjectId >0)
            {
                BCLDebug.Trace("BINARY", "-----Top Level Object-----"); 
            }
#if _DEBUG 
            binaryArray.Dump(); 
#endif
            binaryArray.Write(this); 

            if (Converter.IsWriteAsByteArray(arrayElemTypeNameInfo.NIprimitiveTypeEnum) && (lowerBound == 0))
            {
                //array is written out as an array of bytes 
                if (arrayElemTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Byte)
                    WriteBytes((Byte[])array); 
                else if (arrayElemTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Char) 
                    WriteChars((char[])array);
                else 
                    WriteArrayAsBytes(array, Converter.TypeLength(arrayElemTypeNameInfo.NIprimitiveTypeEnum));
            }
        }
        internal void WriteRectangleArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int rank, int[] lengthA, int[] lowerBoundA) 
        {
#if _DEBUG
            arrayNameInfo.Dump("WriteRectangleArray arrayNameInfo");
            arrayElemTypeNameInfo.Dump("WriteRectangleArray arrayElemTypeNameInfo"); 
#endif
            InternalWriteItemNull(); 
 
            BinaryArrayTypeEnum binaryArrayTypeEnum = BinaryArrayTypeEnum.Rectangular;
            Object typeInformation = null; 
            int assemId = 0;
            BinaryTypeEnum binaryTypeEnum = BinaryConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo.NItype, objectInfo, arrayElemTypeNameInfo.NIname, objectWriter, out typeInformation, out assemId);

            if (binaryArray == null) 
                binaryArray = new BinaryArray();
 
            for (int i=0; i<rank; i++) 
            {
                if (lowerBoundA[i] != 0) 
                {
                    binaryArrayTypeEnum = BinaryArrayTypeEnum.RectangularOffset;
                    break;
                } 

            } 
 
            binaryArray.Set((int)arrayNameInfo.NIobjectId, rank, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, binaryArrayTypeEnum, assemId);
 
            if (arrayNameInfo.NIobjectId >0)
            {
                BCLDebug.Trace("BINARY", "-----Top Level Object-----");
            } 
#if _DEBUG
            binaryArray.Dump(); 
#endif 
            binaryArray.Write(this);
        } 
Example #18
0
        // Token: 0x0600537F RID: 21375 RVA: 0x00127814 File Offset: 0x00125A14
        private bool CheckForNull(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, object data)
        {
            bool flag = false;

            if (data == null)
            {
                flag = true;
            }
            if (flag && (this.formatterEnums.FEserializerTypeEnum == InternalSerializerTypeE.Binary || memberNameInfo.NIisArrayItem || memberNameInfo.NItransmitTypeOnObject || memberNameInfo.NItransmitTypeOnMember || objectInfo.isSi || this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways)))
            {
                if (typeNameInfo.NIisArrayItem)
                {
                    if (typeNameInfo.NIarrayEnum == InternalArrayTypeE.Single)
                    {
                        this.serWriter.WriteDelayedNullItem();
                    }
                    else
                    {
                        this.serWriter.WriteNullItem(memberNameInfo, typeNameInfo);
                    }
                }
                else
                {
                    this.serWriter.WriteNullMember(memberNameInfo, typeNameInfo);
                }
            }
            return(flag);
        }
        internal void WriteMemberObjectRef(NameInfo memberNameInfo, int idRef) 
        { 
            InternalWriteItemNull();
            if (memberReference == null) 
                memberReference = new MemberReference();
            memberReference.Set(idRef);

            if (memberNameInfo.NIisArrayItem) 
            {
                BCLDebug.Trace("BINARY", "-----item-----"); 
            } 
            else
            { 
                BCLDebug.Trace("BINARY", "-----",memberNameInfo.NIname,"-----");
            }
            memberReference.Dump();
 
            memberReference.Write(this);
        } 
Example #20
0
        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            InternalWriteItemNull();
            int assemId;
            int objectId = (int)nameInfo._objectId;

            string objectName = objectId < 0 ?
                                objectName = typeNameInfo.NIname :         // Nested Object
                                             objectName = nameInfo.NIname; // Non-Nested

            if (_objectMapTable == null)
            {
                _objectMapTable = new Dictionary <string, ObjectMapInfo>();
            }

            ObjectMapInfo objectMapInfo;

            if (_objectMapTable.TryGetValue(objectName, out objectMapInfo) &&
                objectMapInfo.IsCompatible(numMembers, memberNames, memberTypes))
            {
                // Object
                if (_binaryObject == null)
                {
                    _binaryObject = new BinaryObject();
                }

                _binaryObject.Set(objectId, objectMapInfo._objectId);
                _binaryObject.Write(this);
            }
            else if (!typeNameInfo._transmitTypeOnObject)
            {
                // ObjectWithMap
                if (_binaryObjectWithMap == null)
                {
                    _binaryObjectWithMap = new BinaryObjectWithMap();
                }

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

                _binaryObjectWithMap.Write(this);
                if (objectMapInfo == null)
                {
                    _objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
            else
            {
                // ObjectWithMapTyped
                var binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                var typeInformationA = new object[numMembers];
                var assemIdA         = new int[numMembers];
                for (int i = 0; i < numMembers; i++)
                {
                    object typeInformation = null;
                    binaryTypeEnumA[i]  = BinaryTypeConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, _objectWriter, out typeInformation, out assemId);
                    typeInformationA[i] = typeInformation;
                    assemIdA[i]         = assemId;
                }

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

                // BCL types are not placed in table
                assemId = (int)typeNameInfo._assemId;
                _binaryObjectWithMapTyped.Set(objectId, objectName, numMembers, memberNames, binaryTypeEnumA, typeInformationA, assemIdA, assemId);
                _binaryObjectWithMapTyped.Write(this);
                if (objectMapInfo == null)
                {
                    _objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
        }
 internal void WriteNullItem(NameInfo itemNameInfo, NameInfo typeNameInfo)
 { 
     nullCount++; 
     InternalWriteItemNull();
 } 
Example #22
0
        internal void WriteSingleArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound, Array array)
        {
            InternalWriteItemNull();
            BinaryArrayTypeEnum binaryArrayTypeEnum;
            var lengthA = new int[1];

            lengthA[0] = length;
            int[]  lowerBoundA     = null;
            object typeInformation = null;

            if (lowerBound == 0)
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
            }
            else
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.SingleOffset;
                lowerBoundA         = new int[1];
                lowerBoundA[0]      = lowerBound;
            }

            int            assemId;
            BinaryTypeEnum binaryTypeEnum = BinaryTypeConverter.GetBinaryTypeInfo(
                arrayElemTypeNameInfo._type, objectInfo, arrayElemTypeNameInfo.NIname, _objectWriter, out typeInformation, out assemId);

            if (_binaryArray == null)
            {
                _binaryArray = new BinaryArray();
            }
            _binaryArray.Set((int)arrayNameInfo._objectId, 1, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, binaryArrayTypeEnum, assemId);

            _binaryArray.Write(this);

            if (Converter.IsWriteAsByteArray(arrayElemTypeNameInfo._primitiveTypeEnum) && (lowerBound == 0))
            {
                //array is written out as an array of bytes
                if (arrayElemTypeNameInfo._primitiveTypeEnum == InternalPrimitiveTypeE.Byte)
                {
                    WriteBytes((byte[])array);
                }
                else if (arrayElemTypeNameInfo._primitiveTypeEnum == InternalPrimitiveTypeE.Char)
                {
                    WriteChars((char[])array);
                }
                else
                {
                    WriteArrayAsBytes(array, Converter.TypeLength(arrayElemTypeNameInfo._primitiveTypeEnum));
                }
            }
        }
        // Writes a string into the XML stream
        private void WriteString(NameInfo memberNameInfo, NameInfo typeNameInfo, Object stringObject)
        {
            SerTrace.Log( this, "WriteString stringObject ",stringObject," memberName ",memberNameInfo.NIname);
            bool isFirstTime = true;

            long stringId = -1;

            if (!CheckTypeFormat(formatterEnums.FEtypeFormat, FormatterTypeStyle.XsdString))
                stringId= InternalGetId(stringObject, false, null, out isFirstTime);

            typeNameInfo.NIobjectId = stringId;
            SerTrace.Log( this, "WriteString stringId ",stringId," isFirstTime ",isFirstTime);

            if ((isFirstTime) || (stringId < 0))
                serWriter.WriteMemberString(memberNameInfo, typeNameInfo, (String)stringObject);
            else
                WriteObjectRef(memberNameInfo, stringId);
        }
Example #24
0
        internal void WriteJaggedArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound)
        {
            InternalWriteItemNull();
            BinaryArrayTypeEnum binaryArrayTypeEnum;
            var lengthA = new int[1];

            lengthA[0] = length;
            int[]  lowerBoundA     = null;
            object typeInformation = null;
            int    assemId         = 0;

            if (lowerBound == 0)
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.Jagged;
            }
            else
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.JaggedOffset;
                lowerBoundA         = new int[1];
                lowerBoundA[0]      = lowerBound;
            }

            BinaryTypeEnum binaryTypeEnum = BinaryTypeConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo._type, objectInfo, arrayElemTypeNameInfo.NIname, _objectWriter, out typeInformation, out assemId);

            if (_binaryArray == null)
            {
                _binaryArray = new BinaryArray();
            }
            _binaryArray.Set((int)arrayNameInfo._objectId, 1, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, binaryArrayTypeEnum, assemId);

            _binaryArray.Write(this);
        }
 private void TypeToNameInfo(Type type, NameInfo nameInfo)
 {
     TypeToNameInfo(type, null, ToCode(type), nameInfo);
 }
Example #26
0
        internal void WriteRectangleArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int rank, int[] lengthA, int[] lowerBoundA)
        {
            InternalWriteItemNull();

            BinaryArrayTypeEnum binaryArrayTypeEnum = BinaryArrayTypeEnum.Rectangular;
            object         typeInformation          = null;
            int            assemId        = 0;
            BinaryTypeEnum binaryTypeEnum = BinaryTypeConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo._type, objectInfo, arrayElemTypeNameInfo.NIname, _objectWriter, out typeInformation, out assemId);

            if (_binaryArray == null)
            {
                _binaryArray = new BinaryArray();
            }

            for (int i = 0; i < rank; i++)
            {
                if (lowerBoundA[i] != 0)
                {
                    binaryArrayTypeEnum = BinaryArrayTypeEnum.RectangularOffset;
                    break;
                }
            }

            _binaryArray.Set((int)arrayNameInfo._objectId, rank, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, binaryArrayTypeEnum, assemId);
            _binaryArray.Write(this);
        }
        [System.Security.SecurityCritical]  // auto-generated
        private void Write(WriteObjectInfo objectInfo,   
                           NameInfo memberNameInfo,          
                           NameInfo typeNameInfo,            
                           String[] memberNames,             
                           Type[] memberTypes,               
                           Object[] memberData,              
                           WriteObjectInfo[] memberObjectInfos)
        {
            SerTrace.Log( this, "Write 2 Entry obj ",objectInfo.obj,". objectId ",objectInfo.objectId,", objType ",typeNameInfo.NIname,", memberName ",memberNameInfo.NIname,", memberType ",typeNameInfo.NIname);

            int numItems = memberNames.Length;
            NameInfo topNameInfo = null;

            if (memberNameInfo != null)
            {
                SerTrace.Log( this, "Write 2 ObjectBegin, memberName ",memberNameInfo.NIname);
                memberNameInfo.NIobjectId = objectInfo.objectId;
                serWriter.WriteObject(memberNameInfo, typeNameInfo, numItems, memberNames, memberTypes, memberObjectInfos);
            }
            else if ((objectInfo.objectId == topId) && (topName != null))
            {
                SerTrace.Log( this, "Write 2 ObjectBegin, topId method name ",topName);
                topNameInfo = MemberToNameInfo(topName);
                topNameInfo.NIobjectId = objectInfo.objectId;
                serWriter.WriteObject(topNameInfo, typeNameInfo, numItems, memberNames, memberTypes, memberObjectInfos);
            }
            else
            {
                if (!Object.ReferenceEquals(objectInfo.objectType, Converter.typeofString))
                {
                    SerTrace.Log( this, "Write 2 ObjectBegin, default ", typeNameInfo.NIname);
                    typeNameInfo.NIobjectId = objectInfo.objectId;
                    serWriter.WriteObject(typeNameInfo, null, numItems, memberNames, memberTypes, memberObjectInfos);
                }
            }

            if (memberNameInfo.NIisParentTypeOnObject)
            {
                memberNameInfo.NItransmitTypeOnObject = true;
                memberNameInfo.NIisParentTypeOnObject = false;
            }
            else
                memberNameInfo.NItransmitTypeOnObject = false;


            // Write members
            for (int i=0; i<numItems; i++)
            {
                WriteMemberSetup(objectInfo, memberNameInfo, typeNameInfo, memberNames[i], memberTypes[i], memberData[i], memberObjectInfos[i]);
            }

            if (memberNameInfo != null)
            {
                memberNameInfo.NIobjectId = objectInfo.objectId;
                serWriter.WriteObjectEnd(memberNameInfo, typeNameInfo);
            }
            else if ((objectInfo.objectId == topId) && (topName != null))
            {
                serWriter.WriteObjectEnd(topNameInfo, typeNameInfo);
                PutNameInfo(topNameInfo);
            }
            else
            {
                if (!Object.ReferenceEquals(objectInfo.objectType, Converter.typeofString))
                {
                    serWriter.WriteObjectEnd(typeNameInfo, typeNameInfo);                       
                }
            }

            SerTrace.Log( this, "Write 2 Exit");
        }
Example #28
0
 internal void WriteMemberNested(NameInfo memberNameInfo)
 {
     InternalWriteItemNull();
 }
        [System.Security.SecurityCritical]  // auto-generated
        private void WriteArrayMember(WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, Object data)
        {
            SerTrace.Log( this, "WriteArrayMember ",data," baseArrayName ",arrayElemTypeNameInfo.NIname);

            arrayElemTypeNameInfo.NIisArrayItem = true;

            if (CheckForNull(objectInfo, arrayElemTypeNameInfo, arrayElemTypeNameInfo, data))
                return;

            NameInfo actualTypeInfo = null;

            Type dataType = null;

            bool isObjectOnMember = false;

            if (arrayElemTypeNameInfo.NItransmitTypeOnMember)
                isObjectOnMember = true;

            if (!isObjectOnMember && !arrayElemTypeNameInfo.IsSealed)
            {
                dataType = GetType(data);
                if (!Object.ReferenceEquals(arrayElemTypeNameInfo.NItype, dataType))
                    isObjectOnMember = true;
            }

            if (isObjectOnMember)
            {
                // Object array, need type of member
                if ((object)dataType == null)
                    dataType = GetType(data);
                actualTypeInfo = TypeToNameInfo(dataType);
                actualTypeInfo.NItransmitTypeOnMember = true;
                actualTypeInfo.NIobjectId = arrayElemTypeNameInfo.NIobjectId;
                actualTypeInfo.NIassemId = arrayElemTypeNameInfo.NIassemId;
                actualTypeInfo.NIisArrayItem = true;
            }
            else
            {
                actualTypeInfo = arrayElemTypeNameInfo;
                actualTypeInfo.NIisArrayItem = true;
            }

            if (!WriteKnownValueClass(arrayElemTypeNameInfo, actualTypeInfo, data))
            {
                Object obj = data;
                bool assignUniqueIdForValueTypes = false;
                if (Object.ReferenceEquals(arrayElemTypeNameInfo.NItype, Converter.typeofObject))
                    assignUniqueIdForValueTypes = true;

                long arrayId = Schedule(obj, assignUniqueIdForValueTypes, actualTypeInfo.NItype);
                arrayElemTypeNameInfo.NIobjectId = arrayId;
                actualTypeInfo.NIobjectId = arrayId;
                if (arrayId < 1)
                {
                        WriteObjectInfo newObjectInfo = WriteObjectInfo.Serialize(obj, m_surrogates, m_context, serObjectInfoInit, m_formatterConverter, this, m_binder);
                        newObjectInfo.objectId = arrayId;
                        if (!Object.ReferenceEquals(arrayElemTypeNameInfo.NItype, Converter.typeofObject) && (object)Nullable.GetUnderlyingType(arrayElemTypeNameInfo.NItype) == null)
                            newObjectInfo.assemId = actualTypeInfo.NIassemId; 
                        else
                            newObjectInfo.assemId = GetAssemblyId(newObjectInfo);
                        SerTrace.Log( this, "WriteArrayMembers nested");
                        NameInfo typeNameInfo = TypeToNameInfo(newObjectInfo);
                        typeNameInfo.NIobjectId = arrayId;
                        newObjectInfo.objectId = arrayId;
                        Write(newObjectInfo, actualTypeInfo, typeNameInfo);

                        newObjectInfo.ObjectEnd();
                }
                else
                {
                    serWriter.WriteItemObjectRef(arrayElemTypeNameInfo, (int)arrayId);
                }

            }
            if (arrayElemTypeNameInfo.NItransmitTypeOnMember)
                PutNameInfo(actualTypeInfo);
        }
Example #30
0
 internal void WriteMemberString(NameInfo memberNameInfo, NameInfo typeNameInfo, string value)
 {
     InternalWriteItemNull();
     WriteObjectString((int)typeNameInfo._objectId, value);
 }
        //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));
            }
        }
Example #32
0
 internal void WriteNullItem(NameInfo itemNameInfo, NameInfo typeNameInfo)
 {
     _consecutiveNullArrayEntryCount++;
     InternalWriteItemNull();
 }
        internal void WriteJaggedArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound) 
        {
#if _DEBUG 
            arrayNameInfo.Dump("WriteRectangleArray arrayNameInfo"); 
            arrayElemTypeNameInfo.Dump("WriteRectangleArray arrayElemTypeNameInfo");
#endif 
            InternalWriteItemNull();
            BinaryArrayTypeEnum binaryArrayTypeEnum;
            Int32[] lengthA = new Int32[1];
            lengthA[0] = length; 
            Int32[] lowerBoundA = null;
            Object typeInformation = null; 
            int assemId = 0; 

            if (lowerBound == 0) 
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.Jagged;
            }
            else 
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.JaggedOffset; 
                lowerBoundA = new Int32[1]; 
                lowerBoundA[0] = lowerBound;
            } 

            BinaryTypeEnum binaryTypeEnum = BinaryConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo.NItype, objectInfo, arrayElemTypeNameInfo.NIname, objectWriter, out typeInformation, out assemId);

            if (binaryArray == null) 
                binaryArray = new BinaryArray();
            binaryArray.Set((int)arrayNameInfo.NIobjectId, (int)1, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, binaryArrayTypeEnum, assemId); 
 
            if (arrayNameInfo.NIobjectId >0)
            { 
                BCLDebug.Trace("BINARY", "-----Top Level Object-----");
            }
#if _DEBUG
            binaryArray.Dump(); 
#endif
            binaryArray.Write(this); 
        } 
 internal void WriteObjectEnd(NameInfo memberNameInfo, NameInfo typeNameInfo)
 {
 }
        [System.Security.SecurityCritical]  // auto-generated
        internal void WriteObjectByteArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound, Byte[] byteA) 
        {
#if _DEBUG 
            arrayNameInfo.Dump("WriteObjectByteArray arrayNameInfo"); 
            arrayElemTypeNameInfo.Dump("WriteObjectByteArray arrayElemTypeNameInfo");
#endif 
            InternalWriteItemNull();
            WriteSingleArray(memberNameInfo, arrayNameInfo, objectInfo, arrayElemTypeNameInfo, length, lowerBound, byteA);
        }
        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));
            }
        }
        internal void WriteNullMember(NameInfo memberNameInfo, NameInfo typeNameInfo)
        { 
#if _DEBUG
            typeNameInfo.Dump("WriteNullMember typeNameInfo");
#endif
            InternalWriteItemNull(); 
            if (objectNull == null)
                objectNull = new ObjectNull(); 
 
            if (memberNameInfo.NIisArrayItem)
            { 
                BCLDebug.Trace("BINARY",  "-----item-----");
            }
            else
            { 
                objectNull.SetNullCount(1);
                BCLDebug.Trace("BINARY", "-----",memberNameInfo.NIname,"-----"); 
                objectNull.Dump(); 
                objectNull.Write(this);
                nullCount = 0; 
            }
        }
        internal void WriteSingleArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound, Array array)
        {
            this.InternalWriteItemNull();
            int[] lengthA = new int[1] {
                length
            };
            int[]  lowerBoundA     = (int[])null;
            object typeInformation = (object)null;
            BinaryArrayTypeEnum binaryArrayTypeEnum;

            if (lowerBound == 0)
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
            }
            else
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.SingleOffset;
                lowerBoundA         = new int[1] {
                    lowerBound
                };
            }
            int            assemId;
            BinaryTypeEnum binaryTypeInfo = BinaryConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo.NItype, objectInfo, arrayElemTypeNameInfo.NIname, this.objectWriter, out typeInformation, out assemId);

            if (this.binaryArray == null)
            {
                this.binaryArray = new BinaryArray();
            }
            this.binaryArray.Set((int)arrayNameInfo.NIobjectId, 1, lengthA, lowerBoundA, binaryTypeInfo, typeInformation, binaryArrayTypeEnum, assemId);
            long num = arrayNameInfo.NIobjectId;

            this.binaryArray.Write(this);
            if (!Converter.IsWriteAsByteArray(arrayElemTypeNameInfo.NIprimitiveTypeEnum) || lowerBound != 0)
            {
                return;
            }
            if (arrayElemTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Byte)
            {
                this.WriteBytes((byte[])array);
            }
            else if (arrayElemTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Char)
            {
                this.WriteChars((char[])array);
            }
            else
            {
                this.WriteArrayAsBytes(array, Converter.TypeLength(arrayElemTypeNameInfo.NIprimitiveTypeEnum));
            }
        }
 internal void WriteMemberNested(NameInfo memberNameInfo)
 { 
     InternalWriteItemNull();
     if (memberNameInfo.NIisArrayItem)
     {
         BCLDebug.Trace("BINARY", "-----item-----"); 
     }
     else 
     { 
         BCLDebug.Trace("BINARY", "-----",memberNameInfo.NIname,"-----");
     } 
 }
        internal void WriteJaggedArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound)
        {
            this.InternalWriteItemNull();
            int[] lengthA = new int[1] {
                length
            };
            int[]  lowerBoundA     = (int[])null;
            object typeInformation = (object)null;
            int    assemId         = 0;
            BinaryArrayTypeEnum binaryArrayTypeEnum;

            if (lowerBound == 0)
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.Jagged;
            }
            else
            {
                binaryArrayTypeEnum = BinaryArrayTypeEnum.JaggedOffset;
                lowerBoundA         = new int[1] {
                    lowerBound
                };
            }
            BinaryTypeEnum binaryTypeInfo = BinaryConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo.NItype, objectInfo, arrayElemTypeNameInfo.NIname, this.objectWriter, out typeInformation, out assemId);

            if (this.binaryArray == null)
            {
                this.binaryArray = new BinaryArray();
            }
            this.binaryArray.Set((int)arrayNameInfo.NIobjectId, 1, lengthA, lowerBoundA, binaryTypeInfo, typeInformation, binaryArrayTypeEnum, assemId);
            long num = arrayNameInfo.NIobjectId;

            this.binaryArray.Write(this);
        }
 internal void WriteItem(NameInfo itemNameInfo, NameInfo typeNameInfo, Object value)
 { 
     InternalWriteItemNull();
     WriteMember(itemNameInfo, typeNameInfo, value);
 }
        internal void WriteRectangleArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int rank, int[] lengthA, int[] lowerBoundA)
        {
            this.InternalWriteItemNull();
            BinaryArrayTypeEnum binaryArrayTypeEnum = BinaryArrayTypeEnum.Rectangular;
            object         typeInformation          = (object)null;
            int            assemId        = 0;
            BinaryTypeEnum binaryTypeInfo = BinaryConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo.NItype, objectInfo, arrayElemTypeNameInfo.NIname, this.objectWriter, out typeInformation, out assemId);

            if (this.binaryArray == null)
            {
                this.binaryArray = new BinaryArray();
            }
            for (int index = 0; index < rank; ++index)
            {
                if (lowerBoundA[index] != 0)
                {
                    binaryArrayTypeEnum = BinaryArrayTypeEnum.RectangularOffset;
                    break;
                }
            }
            this.binaryArray.Set((int)arrayNameInfo.NIobjectId, rank, lengthA, lowerBoundA, binaryTypeInfo, typeInformation, binaryArrayTypeEnum, assemId);
            long num = arrayNameInfo.NIobjectId;

            this.binaryArray.Write(this);
        }
 internal void WriteItemObjectRef(NameInfo nameInfo, int idRef)
 { 
     InternalWriteItemNull();
     WriteMemberObjectRef(nameInfo, idRef);
 }
 internal void WriteObjectByteArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound, byte[] byteA)
 {
     this.InternalWriteItemNull();
     this.WriteSingleArray(memberNameInfo, arrayNameInfo, objectInfo, arrayElemTypeNameInfo, length, lowerBound, (Array)byteA);
 }
        // Writes an object reference to the stream.
        private void WriteObjectRef(NameInfo nameInfo, long objectId)
        {
            SerTrace.Log( this, "WriteObjectRef Entry ",nameInfo.NIname," ",objectId);
            serWriter.WriteMemberObjectRef(nameInfo, (int)objectId);

            SerTrace.Log( this, "WriteObjectRef Exit ");
        }
 internal void WriteMemberNested(NameInfo memberNameInfo)
 {
     this.InternalWriteItemNull();
     int num = memberNameInfo.NIisArrayItem ? 1 : 0;
 }
        // Writes a null member into the stream
        private bool CheckForNull(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, Object data)
        {
#if _DEBUG            
            SerTrace.Log( this, "CheckForNull Entry data ",Util.PString(data),", memberType ",Util.PString(typeNameInfo.NItype));
#endif
            bool isNull = false;

            if (data == null) // || Convert.IsDBNull(data)
                isNull = true;

            // Optimization, Null members are only written for Binary
            if ((isNull) && (((formatterEnums.FEserializerTypeEnum == InternalSerializerTypeE.Binary)) ||
                             memberNameInfo.NIisArrayItem ||
                             memberNameInfo.NItransmitTypeOnObject ||
                             memberNameInfo.NItransmitTypeOnMember ||
                             objectInfo.isSi ||
                             (CheckTypeFormat(formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways))))
            {
                SerTrace.Log( this, "CheckForNull Write");

                if (typeNameInfo.NIisArrayItem)
                {
                    if (typeNameInfo.NIarrayEnum == InternalArrayTypeE.Single)
                        serWriter.WriteDelayedNullItem();
                    else
                        serWriter.WriteNullItem(memberNameInfo, typeNameInfo);
                }

                else
                    serWriter.WriteNullMember(memberNameInfo, typeNameInfo);
            }
            SerTrace.Log( this, "CheckForNull Exit ",isNull);
            return isNull;
        }
 internal void WriteItem(NameInfo itemNameInfo, NameInfo typeNameInfo, object value)
 {
     this.InternalWriteItemNull();
     this.WriteMember(itemNameInfo, typeNameInfo, value);
 }
 private NameInfo TypeToNameInfo(WriteObjectInfo objectInfo, NameInfo nameInfo)
 {
     return TypeToNameInfo(objectInfo.objectType, objectInfo, ToCode(objectInfo.objectType), nameInfo);
 }
 internal void WriteNullItem(NameInfo itemNameInfo, NameInfo typeNameInfo)
 {
     this.nullCount = this.nullCount + 1;
     this.InternalWriteItemNull();
 }
        private NameInfo GetNameInfo()
        {
            NameInfo nameInfo = null;

            if (!niPool.IsEmpty())
            {
                nameInfo = (NameInfo)niPool.Pop();
                nameInfo.Init();
            }
            else
                nameInfo = new NameInfo();

            return nameInfo;
        }
 internal void WriteItemObjectRef(NameInfo nameInfo, int idRef)
 {
     this.InternalWriteItemNull();
     this.WriteMemberObjectRef(nameInfo, idRef);
 }
        [System.Security.SecurityCritical]  // auto-generated
        private void Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
        {       
#if _DEBUG                        
            SerTrace.Log( this, "Write 1 Entry objectInfo ",objectInfo,", memberNameInfo ",memberNameInfo,", typeNameInfo ",typeNameInfo);
            memberNameInfo.Dump("Write memberNameInfo");
            typeNameInfo.Dump("Write typeNameInfo");
#endif            
            Object obj = objectInfo.obj;
            if (obj==null)
                throw new ArgumentNullException("objectInfo.obj", Environment.GetResourceString("ArgumentNull_Obj"));

            SerTrace.Log( this, "Write 1 objectInfo obj ",objectInfo.obj," objectId ", objectInfo.objectId, " objectType ", objectInfo.objectType);
            Type objType = objectInfo.objectType;
            long objectId = objectInfo.objectId;


            SerTrace.Log( this, "Write 1 ",obj," ObjectId ",objectId);

            if (Object.ReferenceEquals(objType, Converter.typeofString))
            {
                // Top level String
                memberNameInfo.NIobjectId = objectId;
                serWriter.WriteObjectString((int)objectId, obj.ToString());
            }
            else
            {

                if (objectInfo.isArray)
                {
                    WriteArray(objectInfo, memberNameInfo, null); 
                }
                else
                {
                    String[] memberNames;
                    Type[] memberTypes;
                    Object[] memberData;

                    objectInfo.GetMemberInfo(out memberNames, out memberTypes, out memberData);

                    // Only Binary needs to transmit types for ISerializable because the binary formatter transmits the types in URT format.
                    // Soap transmits all types as strings, so it is up to the ISerializable object to convert the string back to its URT type
                    if (objectInfo.isSi || CheckTypeFormat(formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways))
                    {
                        SerTrace.Log( this, "Write 1 TransmitOnObject ");
                        memberNameInfo.NItransmitTypeOnObject = true;
                        memberNameInfo.NIisParentTypeOnObject = true;
                        typeNameInfo.NItransmitTypeOnObject = true;
                        typeNameInfo.NIisParentTypeOnObject = true;                                             
                    }

                    WriteObjectInfo[] memberObjectInfos = new WriteObjectInfo[memberNames.Length];

                    // Get assembly information
                    // Binary Serializer, assembly names need to be
                    // written before objects are referenced.
                    // GetAssemId here will write out the
                    // assemblyStrings at the right Binary
                    // Serialization object boundary.
                    for (int i=0; i<memberTypes.Length; i++)
                    {
                        Type type;
                        if ((object)memberTypes[i] != null)
                            type = memberTypes[i];
                        else if (memberData[i] != null)
                            type = GetType(memberData[i]);
                        else
                            type = Converter.typeofObject;

                        SerTrace.Log( this, "Write 1 member type ",type);
                        InternalPrimitiveTypeE code = ToCode(type);
                        if ((code == InternalPrimitiveTypeE.Invalid) &&
                            (!Object.ReferenceEquals(type, Converter.typeofString)))
                        {
                            SerTrace.Log( this, "Write 1 Create ObjectInfo ", memberTypes[i], " memberData ",memberData[i]);
                            if (memberData[i] != null)
                            {
                                memberObjectInfos[i] =
                                WriteObjectInfo.Serialize
                                (
                                memberData[i],
                                m_surrogates,
                                m_context,
                                serObjectInfoInit,
                                m_formatterConverter,
                                this,
                                m_binder);                                    
                                memberObjectInfos[i].assemId = GetAssemblyId(memberObjectInfos[i]);
                            }
                            else
                            {
                                memberObjectInfos[i] =
                                WriteObjectInfo.Serialize
                                (
                                memberTypes[i],
                                m_surrogates,
                                m_context,
                                serObjectInfoInit,
                                m_formatterConverter,
                                m_binder
                                );
                                memberObjectInfos[i].assemId = GetAssemblyId(memberObjectInfos[i]);
                            }
                        }
                    }           
                    Write(objectInfo, memberNameInfo, typeNameInfo, memberNames, memberTypes, memberData, memberObjectInfos);
                    SerTrace.Log( this, "Write 1 ",obj," type ",GetType(obj));     
                }
            }
            SerTrace.Log( this, "Write 1 Exit ",obj);       
        }
Example #54
0
 private void WriteObjectRef(NameInfo nameInfo, long objectId)
 {
     this.serWriter.WriteMemberObjectRef(nameInfo, (int)objectId);
 }
        [System.Security.SecurityCritical]  // auto-generated
        private void WriteMemberSetup(WriteObjectInfo objectInfo,        
                                      NameInfo memberNameInfo,           
                                      NameInfo typeNameInfo,             
                                      String memberName,             
                                      Type memberType,               
                                      Object memberData,                 
                                      WriteObjectInfo memberObjectInfo
                                     )
        {
            NameInfo newMemberNameInfo = MemberToNameInfo(memberName);
            // newMemberNameInfo contains the member type

            if (memberObjectInfo != null)
                newMemberNameInfo.NIassemId = memberObjectInfo.assemId;
            newMemberNameInfo.NItype = memberType;

            // newTypeNameInfo contains the data type
            NameInfo newTypeNameInfo = null;
            if (memberObjectInfo == null)
            {
                newTypeNameInfo = TypeToNameInfo(memberType);
            }
            else
            {
                newTypeNameInfo = TypeToNameInfo(memberObjectInfo);
            }

            newMemberNameInfo.NItransmitTypeOnObject = memberNameInfo.NItransmitTypeOnObject;
            newMemberNameInfo.NIisParentTypeOnObject = memberNameInfo.NIisParentTypeOnObject;               
            WriteMembers(newMemberNameInfo, newTypeNameInfo, memberData, objectInfo, typeNameInfo, memberObjectInfo);
            PutNameInfo(newMemberNameInfo);
            PutNameInfo(newTypeNameInfo);
        }
Example #56
0
        private void WriteRectangle(WriteObjectInfo objectInfo, int rank, int[] maxA, Array array, NameInfo arrayElemNameTypeInfo, int[] lowerBoundA)
        {
            int[] indices   = new int[rank];
            int[] numArray2 = null;
            bool  flag      = false;

            if (lowerBoundA != null)
            {
                for (int i = 0; i < rank; i++)
                {
                    if (lowerBoundA[i] != 0)
                    {
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                numArray2 = new int[rank];
            }
            bool flag2 = true;

            while (flag2)
            {
                flag2 = false;
                if (flag)
                {
                    for (int k = 0; k < rank; k++)
                    {
                        numArray2[k] = indices[k] + lowerBoundA[k];
                    }
                    this.WriteArrayMember(objectInfo, arrayElemNameTypeInfo, array.GetValue(numArray2));
                }
                else
                {
                    this.WriteArrayMember(objectInfo, arrayElemNameTypeInfo, array.GetValue(indices));
                }
                for (int j = rank - 1; j > -1; j--)
                {
                    if (indices[j] < (maxA[j] - 1))
                    {
                        indices[j]++;
                        if (j < (rank - 1))
                        {
                            for (int m = j + 1; m < rank; m++)
                            {
                                indices[m] = 0;
                            }
                        }
                        flag2 = true;
                        continue;
                    }
                }
            }
        }
        [System.Security.SecurityCritical]  // auto-generated
        private void WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)          
        {
            SerTrace.Log( this, "WriteArray Entry ",objectInfo.obj," ",objectInfo.objectId);

            bool isAllocatedMemberNameInfo = false;
            if (memberNameInfo == null)
            {
                memberNameInfo = TypeToNameInfo(objectInfo);
                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 = null;
            if (!arrayElemType.IsPrimitive)
            {
                arrayElemObjectInfo = WriteObjectInfo.Serialize(arrayElemType, m_surrogates, m_context, serObjectInfoInit, m_formatterConverter, m_binder);
                arrayElemObjectInfo.assemId = GetAssemblyId(arrayElemObjectInfo);
            }


            NameInfo arrayElemTypeNameInfo = null;
            if (arrayElemObjectInfo == null)
                arrayElemTypeNameInfo = TypeToNameInfo(arrayElemType);
            else
                arrayElemTypeNameInfo = TypeToNameInfo(arrayElemObjectInfo);
            arrayElemTypeNameInfo.NIisArray = arrayElemTypeNameInfo.NItype.IsArray;

            NameInfo arrayNameInfo = memberNameInfo;
            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 (arrayElemTypeNameInfo.NIisArray)
            {
                if (rank == 1)
                    arrayEnum = InternalArrayTypeE.Jagged;
                else
                    arrayEnum = InternalArrayTypeE.Rectangular;
            }
            else if (rank == 1)
                arrayEnum = InternalArrayTypeE.Single;
            else
                arrayEnum = InternalArrayTypeE.Rectangular;

            arrayElemTypeNameInfo.NIarrayEnum = arrayEnum;

            SerTrace.Log( this, "WriteArray ArrayInfo type ",arrayType," rank ",rank);


            // Byte array
            if ((Object.ReferenceEquals(arrayElemType, Converter.typeofByte)) && (rank == 1) && (lowerBoundA[0] == 0))
            {
                serWriter.WriteObjectByteArray(memberNameInfo, arrayNameInfo, arrayElemObjectInfo, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0], (byte[])array);
                return;
            }

            if (Object.ReferenceEquals(arrayElemType, Converter.typeofObject) || (object)Nullable.GetUnderlyingType(arrayElemType) != null)
            {
                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
                SerTrace.Log( this, "WriteArray ARRAY_SINGLE ");

                // 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)))
                {
                    Object[] objectA = null;
                    if (!arrayElemType.IsValueType)
                    {
                        // Non-primitive type array                 
                        objectA = (Object[])array;
                    }

                    int upperBound = upperBoundA[0]+1;
                    for (int i = lowerBoundA[0]; i < upperBound; i++)
                    {
                        if (objectA == null)
                            WriteArrayMember(objectInfo, arrayElemTypeNameInfo, array.GetValue(i));
                        else
                            WriteArrayMember(objectInfo, arrayElemTypeNameInfo, objectA[i]);
                    }
                    serWriter.WriteItemEnd();
                }
            }
            else if (arrayEnum == InternalArrayTypeE.Jagged)
            {
                // Jagged Array
                SerTrace.Log( this, "WriteArray ARRAY_JAGGED");

                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]);
                }
                serWriter.WriteItemEnd();
            }
            else
            {
                // Rectangle Array
                // Get the length for all the ranks
                SerTrace.Log( this, "WriteArray ARRAY_RECTANGLE");                      

                arrayNameInfo.NIobjectId = objectId;
                serWriter.WriteRectangleArray(memberNameInfo, arrayNameInfo, arrayElemObjectInfo, arrayElemTypeNameInfo, rank, lengthA, lowerBoundA);

                IndexTraceMessage("WriteArray Rectangle  ", lengthA);

                // Check for a length of zero
                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.WriteItemEnd();
            }

            serWriter.WriteObjectEnd(memberNameInfo, arrayNameInfo); 

            PutNameInfo(arrayElemTypeNameInfo);
            if (isAllocatedMemberNameInfo)
                PutNameInfo(memberNameInfo);

            SerTrace.Log( this, "WriteArray Exit ");
        }
Example #58
0
 private void PutNameInfo(NameInfo nameInfo)
 {
     this.niPool.Push(nameInfo);
 }
        [System.Security.SecurityCritical]  // auto-generated
        private void WriteRectangle(WriteObjectInfo objectInfo, int rank, int[] maxA, System.Array array, NameInfo arrayElemNameTypeInfo, int[] lowerBoundA)
        {
            IndexTraceMessage("WriteRectangle  Entry "+rank, maxA);
            int[] currentA = new int[rank];
            int[] indexMap = null;
            bool isLowerBound = false;
            if (lowerBoundA != null)
            {
                for (int i=0; i<rank; i++)
                {
                    if (lowerBoundA[i] != 0)
                        isLowerBound = true;
                }
            }
            if (isLowerBound)
                indexMap = new int[rank];

            bool isLoop = true;
            while (isLoop)
            {
                isLoop = false;
                if (isLowerBound)
                { 
                    for (int i=0; i<rank; i++)
                    {
                        indexMap[i] = currentA[i]+lowerBoundA[i];
                    }

                    WriteArrayMember(objectInfo, arrayElemNameTypeInfo, array.GetValue(indexMap));
                }
                else
                    WriteArrayMember(objectInfo, arrayElemNameTypeInfo, array.GetValue(currentA));          
                for (int irank = rank-1; irank>-1; irank--)
                {
                    // Find the current or lower dimension which can be incremented.
                    if (currentA[irank] < maxA[irank]-1)
                    {
                        // The current dimension is at maximum. Increase the next lower dimension by 1
                        currentA[irank]++;
                        if (irank < rank-1)
                        {
                            // The current dimension and higher dimensions are zeroed.
                            for (int i = irank+1; i<rank; i++)
                                currentA[i] = 0;
                        }
                        isLoop = true;
                        break;                  
                    }

                }
            }
            SerTrace.Log( this, "WriteRectangle  Exit ");
        }
Example #60
0
        internal void Serialize(object graph, Header[] inHeaders, __BinaryWriter serWriter, bool fCheck)
        {
            if (graph == null)
            {
                throw new ArgumentNullException("graph", Environment.GetResourceString("ArgumentNull_Graph"));
            }
            if (serWriter == null)
            {
                throw new ArgumentNullException("serWriter", Environment.GetResourceString("ArgumentNull_WithParamName", new object[] { "serWriter" }));
            }
            if (fCheck)
            {
                CodeAccessPermission.Demand(PermissionType.SecuritySerialization);
            }
            this.serWriter = serWriter;
            this.headers   = inHeaders;
            serWriter.WriteBegin();
            long headerId          = 0L;
            bool flag2             = false;
            bool flag3             = false;
            IMethodCallMessage mcm = graph as IMethodCallMessage;

            if (mcm != null)
            {
                flag2 = true;
                graph = this.WriteMethodCall(mcm);
            }
            else
            {
                IMethodReturnMessage mrm = graph as IMethodReturnMessage;
                if (mrm != null)
                {
                    flag3 = true;
                    graph = this.WriteMethodReturn(mrm);
                }
            }
            if (graph == null)
            {
                this.WriteSerializedStreamHeader(this.topId, headerId);
                if (flag2)
                {
                    serWriter.WriteMethodCall();
                }
                else if (flag3)
                {
                    serWriter.WriteMethodReturn();
                }
                serWriter.WriteSerializationHeaderEnd();
                serWriter.WriteEnd();
            }
            else
            {
                object obj2;
                long   num2;
                bool   flag;
                this.m_idGenerator        = new ObjectIDGenerator();
                this.m_objectQueue        = new Queue();
                this.m_formatterConverter = new FormatterConverter();
                this.serObjectInfoInit    = new SerObjectInfoInit();
                this.topId = this.InternalGetId(graph, false, null, out flag);
                if (this.headers != null)
                {
                    headerId = this.InternalGetId(this.headers, false, null, out flag);
                }
                else
                {
                    headerId = -1L;
                }
                this.WriteSerializedStreamHeader(this.topId, headerId);
                if (flag2)
                {
                    serWriter.WriteMethodCall();
                }
                else if (flag3)
                {
                    serWriter.WriteMethodReturn();
                }
                if ((this.headers != null) && (this.headers.Length > 0))
                {
                    this.m_objectQueue.Enqueue(this.headers);
                }
                if (graph != null)
                {
                    this.m_objectQueue.Enqueue(graph);
                }
                while ((obj2 = this.GetNext(out num2)) != null)
                {
                    WriteObjectInfo objectInfo = null;
                    if (obj2 is WriteObjectInfo)
                    {
                        objectInfo = (WriteObjectInfo)obj2;
                    }
                    else
                    {
                        objectInfo         = WriteObjectInfo.Serialize(obj2, this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this, this.m_binder);
                        objectInfo.assemId = this.GetAssemblyId(objectInfo);
                    }
                    objectInfo.objectId = num2;
                    NameInfo memberNameInfo = this.TypeToNameInfo(objectInfo);
                    this.Write(objectInfo, memberNameInfo, memberNameInfo);
                    this.PutNameInfo(memberNameInfo);
                    objectInfo.ObjectEnd();
                }
                serWriter.WriteSerializationHeaderEnd();
                serWriter.WriteEnd();
                this.m_objectManager.RaiseOnSerializedEvent();
            }
        }