Exemple #1
0
        public IHandmadeSerializable[] DeserializeArray
        (
            [NotNull] BinaryReader reader
        )
        {
            Sure.NotNull(reader, nameof(reader));

            int    count    = reader.ReadPackedInt32();
            string typeName = reader.ReadString();

            if (PrefixLength == PrefixLength.Short)
            {
                typeName = Namespace + "." + typeName;
            }

            Type type = ReferenceEquals(Assembly, null)
                ? Type.GetType(typeName, true)
                : Assembly.GetType(typeName, true);

            IHandmadeSerializable[] result = new IHandmadeSerializable[count];

            for (int i = 0; i < count; i++)
            {
                IHandmadeSerializable obj = (IHandmadeSerializable)Activator.CreateInstance(type);
                obj.RestoreFromStream(reader);
                result[i] = obj;
            }

            return(result);
        }
Exemple #2
0
        public IHandmadeSerializable Deserialize
        (
            [NotNull] BinaryReader reader
        )
        {
            Sure.NotNull(reader, nameof(reader));

            string typeName = reader.ReadString();

            if (PrefixLength == PrefixLength.Short)
            {
                typeName = Namespace + "." + typeName;
            }

            Type type = ReferenceEquals(Assembly, null)
                ? Type.GetType(typeName, true)
                : Assembly.GetType(typeName, true);

            IHandmadeSerializable result = (IHandmadeSerializable)Activator.CreateInstance(type);

            result.RestoreFromStream(reader);

            return(result);
        }