ObjectEnd() private method

private ObjectEnd ( ) : void
return void
        internal void Serialize(object graph, BinaryFormatterWriter serWriter, bool fCheck)
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }
            if (serWriter == null)
            {
                throw new ArgumentNullException(nameof(serWriter));
            }

            _serWriter = serWriter;

            serWriter.WriteBegin();
            long   headerId = 0;
            object obj;
            long   objectId;
            bool   isNew;

            // allocations if methodCall or methodResponse and no graph
            _idGenerator        = new ObjectIDGenerator();
            _objectQueue        = new Queue <object>();
            _formatterConverter = new FormatterConverter();
            _serObjectInfoInit  = new SerObjectInfoInit();

            _topId   = InternalGetId(graph, false, null, out isNew);
            headerId = -1;
            WriteSerializedStreamHeader(_topId, headerId);

            _objectQueue.Enqueue(graph);
            while ((obj = GetNext(out objectId)) != null)
            {
                WriteObjectInfo objectInfo = null;

                // GetNext will return either an object or a WriteObjectInfo.
                // A WriteObjectInfo is returned if this object was member of another object
                if (obj is WriteObjectInfo)
                {
                    objectInfo = (WriteObjectInfo)obj;
                }
                else
                {
                    objectInfo          = WriteObjectInfo.Serialize(obj, _surrogates, _context, _serObjectInfoInit, _formatterConverter, this, _binder);
                    objectInfo._assemId = GetAssemblyId(objectInfo);
                }

                objectInfo._objectId = objectId;
                NameInfo typeNameInfo = TypeToNameInfo(objectInfo);
                Write(objectInfo, typeNameInfo, typeNameInfo);
                PutNameInfo(typeNameInfo);
                objectInfo.ObjectEnd();
            }

            serWriter.WriteSerializationHeaderEnd();
            serWriter.WriteEnd();

            // Invoke OnSerialized Event
            _objectManager.RaiseOnSerializedEvent();
        }
        [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 ");
        }
        // Writes out an array element
        private void WriteArrayMember(WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, object data)
        {
            arrayElemTypeNameInfo._isArrayItem = true;

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

            NameInfo actualTypeInfo   = null;
            Type     dataType         = null;
            bool     isObjectOnMember = false;

            if (arrayElemTypeNameInfo._transmitTypeOnMember)
            {
                isObjectOnMember = true;
            }

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

            if (isObjectOnMember)
            {
                // Object array, need type of member
                if (dataType == null)
                {
                    dataType = GetType(data);
                }
                actualTypeInfo = TypeToNameInfo(dataType);
                actualTypeInfo._transmitTypeOnMember = true;
                actualTypeInfo._objectId             = arrayElemTypeNameInfo._objectId;
                actualTypeInfo._assemId     = arrayElemTypeNameInfo._assemId;
                actualTypeInfo._isArrayItem = true;
            }
            else
            {
                actualTypeInfo = arrayElemTypeNameInfo;
                actualTypeInfo._isArrayItem = true;
            }

            if (!WriteKnownValueClass(arrayElemTypeNameInfo, actualTypeInfo, data))
            {
                object obj = data;
                bool   assignUniqueIdForValueTypes = false;
                if (ReferenceEquals(arrayElemTypeNameInfo._type, Converter.s_typeofObject))
                {
                    assignUniqueIdForValueTypes = true;
                }

                long arrayId = Schedule(obj, assignUniqueIdForValueTypes, actualTypeInfo._type);
                arrayElemTypeNameInfo._objectId = arrayId;
                actualTypeInfo._objectId        = arrayId;
                if (arrayId < 1)
                {
                    WriteObjectInfo newObjectInfo = WriteObjectInfo.Serialize(obj, _surrogates, _context, _serObjectInfoInit, _formatterConverter, this, _binder);
                    newObjectInfo._objectId = arrayId;
                    newObjectInfo._assemId  = !ReferenceEquals(arrayElemTypeNameInfo._type, Converter.s_typeofObject) && Nullable.GetUnderlyingType(arrayElemTypeNameInfo._type) == null ?
                                              actualTypeInfo._assemId :
                                              GetAssemblyId(newObjectInfo);
                    NameInfo typeNameInfo = TypeToNameInfo(newObjectInfo);
                    typeNameInfo._objectId  = arrayId;
                    newObjectInfo._objectId = arrayId;
                    Write(newObjectInfo, actualTypeInfo, typeNameInfo);
                    newObjectInfo.ObjectEnd();
                }
                else
                {
                    _serWriter.WriteItemObjectRef(arrayElemTypeNameInfo, (int)arrayId);
                }
            }
            if (arrayElemTypeNameInfo._transmitTypeOnMember)
            {
                PutNameInfo(actualTypeInfo);
            }
        }
        // Writes the members of an object
        private void WriteMembers(NameInfo memberNameInfo,
                                  NameInfo memberTypeNameInfo,
                                  object memberData,
                                  WriteObjectInfo objectInfo,
                                  NameInfo typeNameInfo,
                                  WriteObjectInfo memberObjectInfo)
        {
            Type memberType = memberNameInfo._type;
            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 (ReferenceEquals(memberType, Converter.s_typeofObject) || Nullable.GetUnderlyingType(memberType) != null)
            {
                memberTypeNameInfo._transmitTypeOnMember = true;
                memberNameInfo._transmitTypeOnMember     = true;
            }

            if (CheckTypeFormat(_formatterEnums._typeFormat, FormatterTypeStyle.TypesAlways) || (objectInfo._isSi))
            {
                memberTypeNameInfo._transmitTypeOnObject = true;
                memberNameInfo._transmitTypeOnObject     = true;
                memberNameInfo._isParentTypeOnObject     = 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._primitiveTypeEnum == InternalPrimitiveTypeE.Invalid)
            {
                outType = GetType(outObj);
                if (!ReferenceEquals(memberType, outType))
                {
                    memberTypeNameInfo._transmitTypeOnMember = true;
                    memberNameInfo._transmitTypeOnMember     = true;
                }
            }

            if (ReferenceEquals(memberType, Converter.s_typeofObject))
            {
                assignUniqueIdToValueType = true;
                memberType = GetType(memberData);
                if (memberObjectInfo == null)
                {
                    TypeToNameInfo(memberType, memberTypeNameInfo);
                }
                else
                {
                    TypeToNameInfo(memberObjectInfo, memberTypeNameInfo);
                }
            }

            if (memberObjectInfo != null && memberObjectInfo._isArray)
            {
                // Array
                long arrayId = 0;
                if (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
                    memberNameInfo._objectId = arrayId;
                    WriteObjectRef(memberNameInfo, arrayId);
                }
                else
                {
                    // Nested Array
                    _serWriter.WriteMemberNested(memberNameInfo);

                    memberObjectInfo._objectId = arrayId;
                    memberNameInfo._objectId   = arrayId;
                    WriteArray(memberObjectInfo, memberNameInfo, memberObjectInfo);
                    objectInfo.ObjectEnd();
                }
                return;
            }

            if (!WriteKnownValueClass(memberNameInfo, memberTypeNameInfo, memberData))
            {
                if (outType == null)
                {
                    outType = GetType(outObj);
                }

                long memberObjectId = Schedule(outObj, assignUniqueIdToValueType, outType, memberObjectInfo);
                if (memberObjectId < 0)
                {
                    // Nested object
                    memberObjectInfo._objectId = memberObjectId;
                    NameInfo newTypeNameInfo = TypeToNameInfo(memberObjectInfo);
                    newTypeNameInfo._objectId = memberObjectId;
                    Write(memberObjectInfo, memberNameInfo, newTypeNameInfo);
                    PutNameInfo(newTypeNameInfo);
                    memberObjectInfo.ObjectEnd();
                }
                else
                {
                    // Object reference
                    memberNameInfo._objectId = memberObjectId;
                    WriteObjectRef(memberNameInfo, memberObjectId);
                }
            }
        }
示例#5
0
        private void WriteMembers(NameInfo memberNameInfo, NameInfo memberTypeNameInfo, object memberData, WriteObjectInfo objectInfo, NameInfo typeNameInfo, WriteObjectInfo memberObjectInfo)
        {
            Type nItype = memberNameInfo.NItype;
            bool assignUniqueIdToValueType = false;

            if (object.ReferenceEquals(nItype, Converter.typeofObject) || (Nullable.GetUnderlyingType(nItype) != 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))
            {
                object obj2 = memberData;
                Type   objB = null;
                if (memberTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Invalid)
                {
                    objB = this.GetType(obj2);
                    if (!object.ReferenceEquals(nItype, objB))
                    {
                        memberTypeNameInfo.NItransmitTypeOnMember = true;
                        memberNameInfo.NItransmitTypeOnMember     = true;
                    }
                }
                if (object.ReferenceEquals(nItype, Converter.typeofObject))
                {
                    assignUniqueIdToValueType = true;
                    nItype = this.GetType(memberData);
                    if (memberObjectInfo == null)
                    {
                        this.TypeToNameInfo(nItype, memberTypeNameInfo);
                    }
                    else
                    {
                        this.TypeToNameInfo(memberObjectInfo, memberTypeNameInfo);
                    }
                }
                if ((memberObjectInfo != null) && memberObjectInfo.isArray)
                {
                    long objectId = 0L;
                    if (objB == null)
                    {
                        objB = this.GetType(obj2);
                    }
                    objectId = this.Schedule(obj2, false, null, memberObjectInfo);
                    if (objectId > 0L)
                    {
                        memberNameInfo.NIobjectId = objectId;
                        this.WriteObjectRef(memberNameInfo, objectId);
                    }
                    else
                    {
                        this.serWriter.WriteMemberNested(memberNameInfo);
                        memberObjectInfo.objectId = objectId;
                        memberNameInfo.NIobjectId = objectId;
                        this.WriteArray(memberObjectInfo, memberNameInfo, memberObjectInfo);
                        objectInfo.ObjectEnd();
                    }
                }
                else if (!this.WriteKnownValueClass(memberNameInfo, memberTypeNameInfo, memberData))
                {
                    if (objB == null)
                    {
                        objB = this.GetType(obj2);
                    }
                    long num2 = this.Schedule(obj2, assignUniqueIdToValueType, objB, memberObjectInfo);
                    if (num2 < 0L)
                    {
                        memberObjectInfo.objectId = num2;
                        NameInfo info = this.TypeToNameInfo(memberObjectInfo);
                        info.NIobjectId = num2;
                        this.Write(memberObjectInfo, memberNameInfo, info);
                        this.PutNameInfo(info);
                        memberObjectInfo.ObjectEnd();
                    }
                    else
                    {
                        memberNameInfo.NIobjectId = num2;
                        this.WriteObjectRef(memberNameInfo, num2);
                    }
                }
            }
        }
示例#6
0
        // Writes the members of an object
        private void WriteMembers(NameInfo memberNameInfo,
                                  NameInfo memberTypeNameInfo,
                                  object memberData,
                                  WriteObjectInfo objectInfo,
                                  NameInfo typeNameInfo,
                                  WriteObjectInfo memberObjectInfo)
        {
            Type memberType = memberNameInfo._type;
            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 (ReferenceEquals(memberType, Converter.s_typeofObject) || Nullable.GetUnderlyingType(memberType) != null)
            {
                memberTypeNameInfo._transmitTypeOnMember = true;
                memberNameInfo._transmitTypeOnMember = true;
            }

            if (CheckTypeFormat(_formatterEnums._typeFormat, FormatterTypeStyle.TypesAlways) || (objectInfo._isSi))
            {
                memberTypeNameInfo._transmitTypeOnObject = true;
                memberNameInfo._transmitTypeOnObject = true;
                memberNameInfo._isParentTypeOnObject = 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._primitiveTypeEnum == InternalPrimitiveTypeE.Invalid)
            {
                outType = GetType(outObj);
                if (!ReferenceEquals(memberType, outType))
                {
                    memberTypeNameInfo._transmitTypeOnMember = true;
                    memberNameInfo._transmitTypeOnMember = true;
                }
            }

            if (ReferenceEquals(memberType, Converter.s_typeofObject))
            {
                assignUniqueIdToValueType = true;
                memberType = GetType(memberData);
                if (memberObjectInfo == null)
                {
                    TypeToNameInfo(memberType, memberTypeNameInfo);
                }
                else
                {
                    TypeToNameInfo(memberObjectInfo, memberTypeNameInfo);
                }
            }

            if (memberObjectInfo != null && memberObjectInfo._isArray)
            {
                // Array
                long arrayId = 0;
                if (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
                    memberNameInfo._objectId = arrayId;
                    WriteObjectRef(memberNameInfo, arrayId);
                }
                else
                {
                    // Nested Array
                    _serWriter.WriteMemberNested(memberNameInfo);

                    memberObjectInfo._objectId = arrayId;
                    memberNameInfo._objectId = arrayId;
                    WriteArray(memberObjectInfo, memberNameInfo, memberObjectInfo);
                    objectInfo.ObjectEnd();
                }
                return;
            }

            if (!WriteKnownValueClass(memberNameInfo, memberTypeNameInfo, memberData))
            {
                if (outType == null)
                {
                    outType = GetType(outObj);
                }

                long memberObjectId = Schedule(outObj, assignUniqueIdToValueType, outType, memberObjectInfo);
                if (memberObjectId < 0)
                {
                    // Nested object
                    memberObjectInfo._objectId = memberObjectId;
                    NameInfo newTypeNameInfo = TypeToNameInfo(memberObjectInfo);
                    newTypeNameInfo._objectId = memberObjectId;
                    Write(memberObjectInfo, memberNameInfo, newTypeNameInfo);
                    PutNameInfo(newTypeNameInfo);
                    memberObjectInfo.ObjectEnd();
                }
                else
                {
                    // Object reference
                    memberNameInfo._objectId = memberObjectId;
                    WriteObjectRef(memberNameInfo, memberObjectId);
                }
            }
        }
示例#7
0
 private void WriteArrayMember(WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, object data)
 {
     arrayElemTypeNameInfo.NIisArrayItem = true;
     if (!this.CheckForNull(objectInfo, arrayElemTypeNameInfo, arrayElemTypeNameInfo, data))
     {
         NameInfo typeNameInfo = null;
         Type     objB         = null;
         bool     flag         = false;
         if (arrayElemTypeNameInfo.NItransmitTypeOnMember)
         {
             flag = true;
         }
         if (!flag && !arrayElemTypeNameInfo.IsSealed)
         {
             objB = this.GetType(data);
             if (!object.ReferenceEquals(arrayElemTypeNameInfo.NItype, objB))
             {
                 flag = true;
             }
         }
         if (flag)
         {
             if (objB == null)
             {
                 objB = this.GetType(data);
             }
             typeNameInfo = this.TypeToNameInfo(objB);
             typeNameInfo.NItransmitTypeOnMember = true;
             typeNameInfo.NIobjectId             = arrayElemTypeNameInfo.NIobjectId;
             typeNameInfo.NIassemId     = arrayElemTypeNameInfo.NIassemId;
             typeNameInfo.NIisArrayItem = true;
         }
         else
         {
             typeNameInfo = arrayElemTypeNameInfo;
             typeNameInfo.NIisArrayItem = true;
         }
         if (!this.WriteKnownValueClass(arrayElemTypeNameInfo, typeNameInfo, data))
         {
             object obj2 = data;
             bool   assignUniqueIdToValueType = false;
             if (object.ReferenceEquals(arrayElemTypeNameInfo.NItype, Converter.typeofObject))
             {
                 assignUniqueIdToValueType = true;
             }
             long num = this.Schedule(obj2, assignUniqueIdToValueType, typeNameInfo.NItype);
             arrayElemTypeNameInfo.NIobjectId = num;
             typeNameInfo.NIobjectId          = num;
             if (num < 1L)
             {
                 WriteObjectInfo info2 = WriteObjectInfo.Serialize(obj2, this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this, this.m_binder);
                 info2.objectId = num;
                 if (!object.ReferenceEquals(arrayElemTypeNameInfo.NItype, Converter.typeofObject) && (Nullable.GetUnderlyingType(arrayElemTypeNameInfo.NItype) == null))
                 {
                     info2.assemId = typeNameInfo.NIassemId;
                 }
                 else
                 {
                     info2.assemId = this.GetAssemblyId(info2);
                 }
                 NameInfo info3 = this.TypeToNameInfo(info2);
                 info3.NIobjectId = num;
                 info2.objectId   = num;
                 this.Write(info2, typeNameInfo, info3);
                 info2.ObjectEnd();
             }
             else
             {
                 this.serWriter.WriteItemObjectRef(arrayElemTypeNameInfo, (int)num);
             }
         }
         if (arrayElemTypeNameInfo.NItransmitTypeOnMember)
         {
             this.PutNameInfo(typeNameInfo);
         }
     }
 }
示例#8
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();
            }
        }
示例#9
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);
            }
        }
示例#10
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();
        }
 private void WriteMembers(NameInfo memberNameInfo, NameInfo memberTypeNameInfo, object memberData, WriteObjectInfo objectInfo, NameInfo typeNameInfo, WriteObjectInfo memberObjectInfo)
 {
     Type nItype = memberNameInfo.NItype;
     bool assignUniqueIdToValueType = false;
     if (object.ReferenceEquals(nItype, Converter.typeofObject) || (Nullable.GetUnderlyingType(nItype) != 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))
     {
         object obj2 = memberData;
         Type objB = null;
         if (memberTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Invalid)
         {
             objB = this.GetType(obj2);
             if (!object.ReferenceEquals(nItype, objB))
             {
                 memberTypeNameInfo.NItransmitTypeOnMember = true;
                 memberNameInfo.NItransmitTypeOnMember = true;
             }
         }
         if (object.ReferenceEquals(nItype, Converter.typeofObject))
         {
             assignUniqueIdToValueType = true;
             nItype = this.GetType(memberData);
             if (memberObjectInfo == null)
             {
                 this.TypeToNameInfo(nItype, memberTypeNameInfo);
             }
             else
             {
                 this.TypeToNameInfo(memberObjectInfo, memberTypeNameInfo);
             }
         }
         if ((memberObjectInfo != null) && memberObjectInfo.isArray)
         {
             long objectId = 0L;
             if (objB == null)
             {
                 objB = this.GetType(obj2);
             }
             objectId = this.Schedule(obj2, false, null, memberObjectInfo);
             if (objectId > 0L)
             {
                 memberNameInfo.NIobjectId = objectId;
                 this.WriteObjectRef(memberNameInfo, objectId);
             }
             else
             {
                 this.serWriter.WriteMemberNested(memberNameInfo);
                 memberObjectInfo.objectId = objectId;
                 memberNameInfo.NIobjectId = objectId;
                 this.WriteArray(memberObjectInfo, memberNameInfo, memberObjectInfo);
                 objectInfo.ObjectEnd();
             }
         }
         else if (!this.WriteKnownValueClass(memberNameInfo, memberTypeNameInfo, memberData))
         {
             if (objB == null)
             {
                 objB = this.GetType(obj2);
             }
             long num2 = this.Schedule(obj2, assignUniqueIdToValueType, objB, memberObjectInfo);
             if (num2 < 0L)
             {
                 memberObjectInfo.objectId = num2;
                 NameInfo info = this.TypeToNameInfo(memberObjectInfo);
                 info.NIobjectId = num2;
                 this.Write(memberObjectInfo, memberNameInfo, info);
                 this.PutNameInfo(info);
                 memberObjectInfo.ObjectEnd();
             }
             else
             {
                 memberNameInfo.NIobjectId = num2;
                 this.WriteObjectRef(memberNameInfo, num2);
             }
         }
     }
 }