Exemplo n.º 1
0
        private static object ReadSerialized(BinaryReader reader, bool isNull, out Type objectType)
        {
            var typeName = reader.ReadString();

            objectType = Type.GetType(typeName, true, true);

            if (isNull)
            {
                return(null);
            }

            var type = objectType;

            if (!SerializerUtil.IsInstantiable(objectType))
            {
                var realTypeName = reader.ReadString();
                type = Type.GetType(realTypeName, true, true);
            }

            var memberCount = reader.ReadInt32();
            var info        = new SerializationInfo(objectType);

            for (int i = 0; i < memberCount; i++)
            {
                ReadMember(reader, info);
            }

            return(SerializerUtil.CreateObject(type, info));
        }
Exemplo n.º 2
0
        private static void WriteSerializable(BinaryWriter writer, Type objectType, object obj)
        {
            writer.Write(objectType.AssemblyQualifiedName);

            if (obj == null)
            {
                return;
            }

            if (!SerializerUtil.IsInstantiable(objectType))
            {
                writer.Write(obj.GetType().AssemblyQualifiedName);
            }

            var info = new SerializationInfo(objectType);

            ((ISerializable)obj).GetObjectData(info);

            writer.Write(info.MemberCount);

            foreach (var memberInfo in info)
            {
                WriteMember(writer, memberInfo);
            }
        }