Serialize() статический приватный Метод

static private Serialize ( Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder ) : WriteObjectInfo
objectType System.Type
surrogateSelector ISurrogateSelector
context System.Runtime.Serialization.StreamingContext
serObjectInfoInit SerObjectInfoInit
converter IFormatterConverter
binder System.Runtime.Serialization.SerializationBinder
Результат WriteObjectInfo
Пример #1
0
        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();
        }
Пример #2
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 type1 = objectInfo.objectType;
            long num   = objectInfo.objectId;
            Type type2 = Converter.typeofString;

            if (type1 == type2)
            {
                memberNameInfo.NIobjectId = num;
                this.serWriter.WriteObjectString((int)num, obj.ToString());
            }
            else if (objectInfo.isArray)
            {
                this.WriteArray(objectInfo, memberNameInfo, (WriteObjectInfo)null);
            }
            else
            {
                string[] outMemberNames;
                Type[]   outMemberTypes;
                object[] outMemberData;
                objectInfo.GetMemberInfo(out outMemberNames, out outMemberTypes, out outMemberData);
                if (objectInfo.isSi || this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways))
                {
                    memberNameInfo.NItransmitTypeOnObject = true;
                    memberNameInfo.NIisParentTypeOnObject = true;
                    typeNameInfo.NItransmitTypeOnObject   = true;
                    typeNameInfo.NIisParentTypeOnObject   = true;
                }
                WriteObjectInfo[] memberObjectInfos = new WriteObjectInfo[outMemberNames.Length];
                for (int index = 0; index < outMemberTypes.Length; ++index)
                {
                    Type type3 = outMemberTypes[index] == null ? (outMemberData[index] == null ? Converter.typeofObject : this.GetType(outMemberData[index])) : outMemberTypes[index];
                    if (this.ToCode(type3) == InternalPrimitiveTypeE.Invalid && type3 != Converter.typeofString)
                    {
                        if (outMemberData[index] != null)
                        {
                            memberObjectInfos[index]         = WriteObjectInfo.Serialize(outMemberData[index], this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this, this.m_binder);
                            memberObjectInfos[index].assemId = this.GetAssemblyId(memberObjectInfos[index]);
                        }
                        else
                        {
                            memberObjectInfos[index]         = WriteObjectInfo.Serialize(outMemberTypes[index], this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this.m_binder);
                            memberObjectInfos[index].assemId = this.GetAssemblyId(memberObjectInfos[index]);
                        }
                    }
                }
                this.Write(objectInfo, memberNameInfo, typeNameInfo, outMemberNames, outMemberTypes, outMemberData, memberObjectInfos);
            }
        }
Пример #3
0
        // 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);
            }
        }
Пример #4
0
        // Writes out an array
        private void WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
        {
            bool isAllocatedMemberNameInfo = false;

            if (memberNameInfo == null)
            {
                memberNameInfo            = TypeToNameInfo(objectInfo);
                isAllocatedMemberNameInfo = true;
            }

            memberNameInfo._isArray = true;

            long objectId = objectInfo._objectId;

            memberNameInfo._objectId = objectInfo._objectId;

            // Get array type
            Array array = (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, _surrogates, _context, _serObjectInfoInit, _formatterConverter, _binder);
                arrayElemObjectInfo._assemId = GetAssemblyId(arrayElemObjectInfo);
            }

            NameInfo arrayElemTypeNameInfo = arrayElemObjectInfo == null?
                                             TypeToNameInfo(arrayElemType) :
                                                 TypeToNameInfo(arrayElemObjectInfo);

            arrayElemTypeNameInfo._isArray = arrayElemTypeNameInfo._type.IsArray;

            NameInfo arrayNameInfo = memberNameInfo;

            arrayNameInfo._objectId                     = objectId;
            arrayNameInfo._isArray                      = true;
            arrayElemTypeNameInfo._objectId             = objectId;
            arrayElemTypeNameInfo._transmitTypeOnMember = memberNameInfo._transmitTypeOnMember;
            arrayElemTypeNameInfo._transmitTypeOnObject = memberNameInfo._transmitTypeOnObject;
            arrayElemTypeNameInfo._isParentTypeOnObject = memberNameInfo._isParentTypeOnObject;

            // 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._isArray)
            {
                arrayEnum = rank == 1 ? InternalArrayTypeE.Jagged : InternalArrayTypeE.Rectangular;
            }
            else if (rank == 1)
            {
                arrayEnum = InternalArrayTypeE.Single;
            }
            else
            {
                arrayEnum = InternalArrayTypeE.Rectangular;
            }
            arrayElemTypeNameInfo._arrayEnum = arrayEnum;

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

            if (ReferenceEquals(arrayElemType, Converter.s_typeofObject) || Nullable.GetUnderlyingType(arrayElemType) != null)
            {
                memberNameInfo._transmitTypeOnMember        = true;
                arrayElemTypeNameInfo._transmitTypeOnMember = true;
            }

            if (CheckTypeFormat(_formatterEnums._typeFormat, FormatterTypeStyle.TypesAlways))
            {
                memberNameInfo._transmitTypeOnObject        = true;
                arrayElemTypeNameInfo._transmitTypeOnObject = true;
            }

            if (arrayEnum == InternalArrayTypeE.Single)
            {
                // Single Dimensional array

                // 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._primitiveTypeEnum) && (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

                arrayNameInfo._objectId = objectId;

                _serWriter.WriteJaggedArray(memberNameInfo, arrayNameInfo, arrayElemObjectInfo, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0]);

                var 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

                arrayNameInfo._objectId = objectId;
                _serWriter.WriteRectangleArray(memberNameInfo, arrayNameInfo, arrayElemObjectInfo, arrayElemTypeNameInfo, rank, lengthA, lowerBoundA);

                // 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);
            }
        }
Пример #5
0
        // Writes a given object to the stream.
        private void Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
        {
            object obj = objectInfo._obj;

            if (obj == null)
            {
                throw new ArgumentNullException(nameof(objectInfo) + "." + nameof(objectInfo._obj));
            }
            Type objType  = objectInfo._objectType;
            long objectId = objectInfo._objectId;

            if (ReferenceEquals(objType, Converter.s_typeofString))
            {
                // Top level String
                memberNameInfo._objectId = 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._typeFormat, FormatterTypeStyle.TypesAlways))
                    {
                        memberNameInfo._transmitTypeOnObject = true;
                        memberNameInfo._isParentTypeOnObject = true;
                        typeNameInfo._transmitTypeOnObject   = true;
                        typeNameInfo._isParentTypeOnObject   = true;
                    }

                    var 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 =
                            memberTypes[i] != null ? memberTypes[i] :
                            memberData[i] != null?GetType(memberData[i]) :
                                Converter.s_typeofObject;

                        InternalPrimitiveTypeE code = ToCode(type);
                        if ((code == InternalPrimitiveTypeE.Invalid) &&
                            (!ReferenceEquals(type, Converter.s_typeofString)))
                        {
                            if (memberData[i] != null)
                            {
                                memberObjectInfos[i] = WriteObjectInfo.Serialize(
                                    memberData[i],
                                    _surrogates,
                                    _context,
                                    _serObjectInfoInit,
                                    _formatterConverter,
                                    this,
                                    _binder);
                                memberObjectInfos[i]._assemId = GetAssemblyId(memberObjectInfos[i]);
                            }
                            else
                            {
                                memberObjectInfos[i] = WriteObjectInfo.Serialize(
                                    memberTypes[i],
                                    _surrogates,
                                    _context,
                                    _serObjectInfoInit,
                                    _formatterConverter,
                                    _binder);
                                memberObjectInfos[i]._assemId = GetAssemblyId(memberObjectInfos[i]);
                            }
                        }
                    }
                    Write(objectInfo, memberNameInfo, typeNameInfo, memberNames, memberTypes, memberData, memberObjectInfos);
                }
            }
        }
Пример #6
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);
         }
     }
 }
Пример #7
0
        private void WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
        {
            InternalArrayTypeE jagged;
            bool flag2;
            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            elementType = objectInfo.objectType.GetElementType();
            WriteObjectInfo info        = null;

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

            if (info == null)
            {
                arrayElemTypeNameInfo = this.TypeToNameInfo(elementType);
            }
            else
            {
                arrayElemTypeNameInfo = this.TypeToNameInfo(info);
            }
            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;
            int rank = array.Rank;

            int[] lengthA     = new int[rank];
            int[] lowerBoundA = new int[rank];
            int[] numArray3   = new int[rank];
            for (int i = 0; i < rank; i++)
            {
                lengthA[i]     = array.GetLength(i);
                lowerBoundA[i] = array.GetLowerBound(i);
                numArray3[i]   = array.GetUpperBound(i);
            }
            if (arrayElemTypeNameInfo.NIisArray)
            {
                if (rank == 1)
                {
                    jagged = InternalArrayTypeE.Jagged;
                }
                else
                {
                    jagged = InternalArrayTypeE.Rectangular;
                }
            }
            else if (rank == 1)
            {
                jagged = InternalArrayTypeE.Single;
            }
            else
            {
                jagged = InternalArrayTypeE.Rectangular;
            }
            arrayElemTypeNameInfo.NIarrayEnum = jagged;
            if ((object.ReferenceEquals(elementType, Converter.typeofByte) && (rank == 1)) && (lowerBoundA[0] == 0))
            {
                this.serWriter.WriteObjectByteArray(memberNameInfo, arrayNameInfo, info, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0], (byte[])array);
                return;
            }
            if (object.ReferenceEquals(elementType, Converter.typeofObject) || (Nullable.GetUnderlyingType(elementType) != null))
            {
                memberNameInfo.NItransmitTypeOnMember        = true;
                arrayElemTypeNameInfo.NItransmitTypeOnMember = true;
            }
            if (this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways))
            {
                memberNameInfo.NItransmitTypeOnObject        = true;
                arrayElemTypeNameInfo.NItransmitTypeOnObject = true;
            }
            switch (jagged)
            {
            case InternalArrayTypeE.Single:
                this.serWriter.WriteSingleArray(memberNameInfo, arrayNameInfo, info, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0], array);
                if (!Converter.IsWriteAsByteArray(arrayElemTypeNameInfo.NIprimitiveTypeEnum) || (lowerBoundA[0] != 0))
                {
                    object[] objArray = null;
                    if (!elementType.IsValueType)
                    {
                        objArray = (object[])array;
                    }
                    int num4 = numArray3[0] + 1;
                    for (int j = lowerBoundA[0]; j < num4; j++)
                    {
                        if (objArray == null)
                        {
                            this.WriteArrayMember(objectInfo, arrayElemTypeNameInfo, array.GetValue(j));
                        }
                        else
                        {
                            this.WriteArrayMember(objectInfo, arrayElemTypeNameInfo, objArray[j]);
                        }
                    }
                    this.serWriter.WriteItemEnd();
                }
                goto Label_0365;

            case InternalArrayTypeE.Jagged:
            {
                arrayNameInfo.NIobjectId = objectId;
                this.serWriter.WriteJaggedArray(memberNameInfo, arrayNameInfo, info, arrayElemTypeNameInfo, lengthA[0], lowerBoundA[0]);
                object[] objArray2 = (object[])array;
                for (int k = lowerBoundA[0]; k < (numArray3[0] + 1); k++)
                {
                    this.WriteArrayMember(objectInfo, arrayElemTypeNameInfo, objArray2[k]);
                }
                this.serWriter.WriteItemEnd();
                goto Label_0365;
            }

            default:
                arrayNameInfo.NIobjectId = objectId;
                this.serWriter.WriteRectangleArray(memberNameInfo, arrayNameInfo, info, arrayElemTypeNameInfo, rank, lengthA, lowerBoundA);
                flag2 = false;
                for (int m = 0; m < rank; m++)
                {
                    if (lengthA[m] == 0)
                    {
                        flag2 = true;
                        break;
                    }
                }
                break;
            }
            if (!flag2)
            {
                this.WriteRectangle(objectInfo, rank, lengthA, array, arrayElemTypeNameInfo, lowerBoundA);
            }
            this.serWriter.WriteItemEnd();
Label_0365:
            this.serWriter.WriteObjectEnd(memberNameInfo, arrayNameInfo);
            this.PutNameInfo(arrayElemTypeNameInfo);
            if (flag)
            {
                this.PutNameInfo(memberNameInfo);
            }
        }
Пример #8
0
        private void Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
        {
            object obj2 = objectInfo.obj;

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

            if (object.ReferenceEquals(objectType, Converter.typeofString))
            {
                memberNameInfo.NIobjectId = objectId;
                this.serWriter.WriteObjectString((int)objectId, obj2.ToString());
            }
            else if (objectInfo.isArray)
            {
                this.WriteArray(objectInfo, memberNameInfo, null);
            }
            else
            {
                string[] strArray;
                Type[]   typeArray;
                object[] objArray;
                objectInfo.GetMemberInfo(out strArray, out typeArray, out objArray);
                if (objectInfo.isSi || this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways))
                {
                    memberNameInfo.NItransmitTypeOnObject = true;
                    memberNameInfo.NIisParentTypeOnObject = true;
                    typeNameInfo.NItransmitTypeOnObject   = true;
                    typeNameInfo.NIisParentTypeOnObject   = true;
                }
                WriteObjectInfo[] memberObjectInfos = new WriteObjectInfo[strArray.Length];
                for (int i = 0; i < typeArray.Length; i++)
                {
                    Type type;
                    if (typeArray[i] != null)
                    {
                        type = typeArray[i];
                    }
                    else if (objArray[i] != null)
                    {
                        type = this.GetType(objArray[i]);
                    }
                    else
                    {
                        type = Converter.typeofObject;
                    }
                    if ((this.ToCode(type) == InternalPrimitiveTypeE.Invalid) && !object.ReferenceEquals(type, Converter.typeofString))
                    {
                        if (objArray[i] != null)
                        {
                            memberObjectInfos[i]         = WriteObjectInfo.Serialize(objArray[i], this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this, this.m_binder);
                            memberObjectInfos[i].assemId = this.GetAssemblyId(memberObjectInfos[i]);
                        }
                        else
                        {
                            memberObjectInfos[i]         = WriteObjectInfo.Serialize(typeArray[i], this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this.m_binder);
                            memberObjectInfos[i].assemId = this.GetAssemblyId(memberObjectInfos[i]);
                        }
                    }
                }
                this.Write(objectInfo, memberNameInfo, typeNameInfo, strArray, typeArray, objArray, memberObjectInfos);
            }
        }
Пример #9
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();
            }
        }
Пример #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);
            }
        }
Пример #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);
            }
        }
Пример #12
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);
        }
Пример #13
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", (object)"serWriter"));
            }
            if (fCheck)
            {
                CodeAccessPermission.Demand(PermissionType.SecuritySerialization);
            }
            this.serWriter = serWriter;
            this.headers   = inHeaders;
            serWriter.WriteBegin();
            long headerId          = 0;
            bool flag1             = false;
            bool flag2             = false;
            IMethodCallMessage mcm = graph as IMethodCallMessage;

            if (mcm != null)
            {
                flag1 = true;
                graph = (object)this.WriteMethodCall(mcm);
            }
            else
            {
                IMethodReturnMessage mrm = graph as IMethodReturnMessage;
                if (mrm != null)
                {
                    flag2 = true;
                    graph = (object)this.WriteMethodReturn(mrm);
                }
            }
            if (graph == null)
            {
                this.WriteSerializedStreamHeader(this.topId, headerId);
                if (flag1)
                {
                    serWriter.WriteMethodCall();
                }
                else if (flag2)
                {
                    serWriter.WriteMethodReturn();
                }
                serWriter.WriteSerializationHeaderEnd();
                serWriter.WriteEnd();
            }
            else
            {
                this.m_idGenerator        = new ObjectIDGenerator();
                this.m_objectQueue        = new Queue();
                this.m_formatterConverter = (IFormatterConverter) new FormatterConverter();
                this.serObjectInfoInit    = new SerObjectInfoInit();
                bool isNew;
                this.topId = this.InternalGetId(graph, false, (Type)null, out isNew);
                this.WriteSerializedStreamHeader(this.topId, this.headers == null ? -1L : this.InternalGetId((object)this.headers, false, (Type)null, out isNew));
                if (flag1)
                {
                    serWriter.WriteMethodCall();
                }
                else if (flag2)
                {
                    serWriter.WriteMethodReturn();
                }
                if (this.headers != null && this.headers.Length != 0)
                {
                    this.m_objectQueue.Enqueue((object)this.headers);
                }
                if (graph != null)
                {
                    this.m_objectQueue.Enqueue(graph);
                }
                object next;
                long   objID;
                while ((next = this.GetNext(out objID)) != null)
                {
                    WriteObjectInfo objectInfo1;
                    if (next is WriteObjectInfo)
                    {
                        objectInfo1 = (WriteObjectInfo)next;
                    }
                    else
                    {
                        objectInfo1         = WriteObjectInfo.Serialize(next, this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this, this.m_binder);
                        objectInfo1.assemId = this.GetAssemblyId(objectInfo1);
                    }
                    objectInfo1.objectId = objID;
                    NameInfo        nameInfo1   = this.TypeToNameInfo(objectInfo1);
                    WriteObjectInfo objectInfo2 = objectInfo1;
                    NameInfo        nameInfo2   = nameInfo1;
                    this.Write(objectInfo2, nameInfo2, nameInfo2);
                    this.PutNameInfo(nameInfo1);
                    objectInfo1.ObjectEnd();
                }
                serWriter.WriteSerializationHeaderEnd();
                serWriter.WriteEnd();
                this.m_objectManager.RaiseOnSerializedEvent();
            }
        }
Пример #14
0
        private void WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
        {
            bool flag1 = false;

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

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

            if (!elementType.IsPrimitive)
            {
                objectInfo1         = WriteObjectInfo.Serialize(elementType, this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, this.m_binder);
                objectInfo1.assemId = this.GetAssemblyId(objectInfo1);
            }
            NameInfo nameInfo1 = objectInfo1 != null?this.TypeToNameInfo(objectInfo1) : this.TypeToNameInfo(elementType);

            NameInfo nameInfo2 = nameInfo1;
            int      num2      = nameInfo2.NItype.IsArray ? 1 : 0;

            nameInfo2.NIisArray = num2 != 0;
            NameInfo nameInfo3 = memberNameInfo;

            nameInfo3.NIobjectId             = num1;
            nameInfo3.NIisArray              = true;
            nameInfo1.NIobjectId             = num1;
            nameInfo1.NItransmitTypeOnMember = memberNameInfo.NItransmitTypeOnMember;
            nameInfo1.NItransmitTypeOnObject = memberNameInfo.NItransmitTypeOnObject;
            nameInfo1.NIisParentTypeOnObject = memberNameInfo.NIisParentTypeOnObject;
            int rank = array.Rank;

            int[] numArray1   = new int[rank];
            int[] lowerBoundA = new int[rank];
            int[] numArray2   = new int[rank];
            for (int dimension = 0; dimension < rank; ++dimension)
            {
                numArray1[dimension]   = array.GetLength(dimension);
                lowerBoundA[dimension] = array.GetLowerBound(dimension);
                numArray2[dimension]   = array.GetUpperBound(dimension);
            }
            InternalArrayTypeE internalArrayTypeE = !nameInfo1.NIisArray ? (rank != 1 ? InternalArrayTypeE.Rectangular : InternalArrayTypeE.Single) : (rank != 1 ? InternalArrayTypeE.Rectangular : InternalArrayTypeE.Jagged);

            nameInfo1.NIarrayEnum = internalArrayTypeE;
            if (elementType == Converter.typeofByte && rank == 1 && lowerBoundA[0] == 0)
            {
                this.serWriter.WriteObjectByteArray(memberNameInfo, nameInfo3, objectInfo1, nameInfo1, numArray1[0], lowerBoundA[0], (byte[])array);
            }
            else
            {
                if (elementType == Converter.typeofObject || Nullable.GetUnderlyingType(elementType) != null)
                {
                    memberNameInfo.NItransmitTypeOnMember = true;
                    nameInfo1.NItransmitTypeOnMember      = true;
                }
                if (this.CheckTypeFormat(this.formatterEnums.FEtypeFormat, FormatterTypeStyle.TypesAlways))
                {
                    memberNameInfo.NItransmitTypeOnObject = true;
                    nameInfo1.NItransmitTypeOnObject      = true;
                }
                if (internalArrayTypeE == InternalArrayTypeE.Single)
                {
                    this.serWriter.WriteSingleArray(memberNameInfo, nameInfo3, objectInfo1, nameInfo1, numArray1[0], lowerBoundA[0], array);
                    if (!Converter.IsWriteAsByteArray(nameInfo1.NIprimitiveTypeEnum) || lowerBoundA[0] != 0)
                    {
                        object[] objArray = (object[])null;
                        if (!elementType.IsValueType)
                        {
                            objArray = (object[])array;
                        }
                        int num3 = numArray2[0] + 1;
                        for (int index = lowerBoundA[0]; index < num3; ++index)
                        {
                            if (objArray == null)
                            {
                                this.WriteArrayMember(objectInfo, nameInfo1, array.GetValue(index));
                            }
                            else
                            {
                                this.WriteArrayMember(objectInfo, nameInfo1, objArray[index]);
                            }
                        }
                        this.serWriter.WriteItemEnd();
                    }
                }
                else if (internalArrayTypeE == InternalArrayTypeE.Jagged)
                {
                    nameInfo3.NIobjectId = num1;
                    this.serWriter.WriteJaggedArray(memberNameInfo, nameInfo3, objectInfo1, nameInfo1, numArray1[0], lowerBoundA[0]);
                    object[] objArray = (object[])array;
                    for (int index = lowerBoundA[0]; index < numArray2[0] + 1; ++index)
                    {
                        this.WriteArrayMember(objectInfo, nameInfo1, objArray[index]);
                    }
                    this.serWriter.WriteItemEnd();
                }
                else
                {
                    nameInfo3.NIobjectId = num1;
                    this.serWriter.WriteRectangleArray(memberNameInfo, nameInfo3, objectInfo1, nameInfo1, rank, numArray1, lowerBoundA);
                    bool flag2 = false;
                    for (int index = 0; index < rank; ++index)
                    {
                        if (numArray1[index] == 0)
                        {
                            flag2 = true;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        this.WriteRectangle(objectInfo, rank, numArray1, array, nameInfo1, lowerBoundA);
                    }
                    this.serWriter.WriteItemEnd();
                }
                this.serWriter.WriteObjectEnd(memberNameInfo, nameInfo3);
                this.PutNameInfo(nameInfo1);
                if (!flag1)
                {
                    return;
                }
                this.PutNameInfo(memberNameInfo);
            }
        }