Ejemplo n.º 1
0
        private void InitSiWrite()
        {
            SerTrace.Log(this, objectInfoId, " InitSiWrite Entry ");

            SerializationInfoEnumerator siEnum = null;

            isSi   = true;
            siEnum = si.GetEnumerator();
            int infoLength = 0;

            infoLength = si.MemberCount;

            int count = infoLength;

            // For ISerializable cache cannot be saved because each object instance can have different values
            // BinaryWriter only puts the map on the wire if the ISerializable map cannot be reused.
            TypeInformation typeInformation = null;
            //string fullTypeName = si.FullTypeName;

            // Using simple type rather than using full assembly name

            /*
             * string fullTypeName = si.FullTypeName;
             *
             * string assemblyString = si.AssemblyName;
             */

            string fullTypeName = BinaryMinifier.FullTypeNameMinifier(si.FullTypeName, si.AssemblyName);

            string assemblyString = BinaryMinifier.AssemblyOrTypeNameMinifier(si.AssemblyName);

            bool hasTypeForwardedFrom = false;

            if (!si.IsFullTypeNameSetExplicit)
            {
                typeInformation = BinaryFormatter.GetTypeInformation(si.ObjectType);
                //fullTypeName = typeInformation.FullTypeName;
                fullTypeName         = BinaryMinifier.FullTypeNameMinifier(typeInformation.FullTypeName, typeInformation.AssemblyString);
                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }

            if (!si.IsAssemblyNameSetExplicit)
            {
                if (typeInformation == null)
                {
                    typeInformation = BinaryFormatter.GetTypeInformation(si.ObjectType);
                }
                assemblyString = BinaryMinifier.AssemblyOrTypeNameMinifier(typeInformation.AssemblyString);

                //assemblyString = typeInformation.AssemblyString;

                hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
            }

            cache = new SerObjectInfoCache(fullTypeName, assemblyString, hasTypeForwardedFrom);

            cache.memberNames = new String[count];
            cache.memberTypes = new Type[count];
            memberData        = new Object[count];

            siEnum = si.GetEnumerator();
            for (int i = 0; siEnum.MoveNext(); i++)
            {
                cache.memberNames[i] = siEnum.Name;
                cache.memberTypes[i] = siEnum.ObjectType;
                memberData[i]        = siEnum.Value;
                SerTrace.Log(this, objectInfoId + " ", objectType, " InitSiWrite ", cache.memberNames[i], " Type ", cache.memberTypes[i], " data ", memberData[i]);
            }

            isNamed = true;
            isTyped = false;

            SerTrace.Log(this, objectInfoId, " InitSiWrite Exit ");
        }