Ejemplo n.º 1
0
        public override void DeserializeOverride(StreamLimiter stream, EventShuttle eventShuttle)
        {
            var serializationContext = CreateSerializationContext();

            _binarySerializable = (IBinarySerializable)Activator.CreateInstance(TypeNode.Type);
            _binarySerializable.Deserialize(stream.BaseStream, Endianness, serializationContext);
        }
Ejemplo n.º 2
0
        public void ReadFile(string path, IBinarySerializable value)
        {
            int size = _fileSystem.GetFileSize(path);

            using (var stream = _fileSystem.OpenFile(path))
            {
                value.Deserialize(stream, size);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads the object.
        /// </summary>
        /// <returns></returns>
        public IBinarySerializable ReadObject()
        {
            int classId = ReadClassId();

            if (classId == 0)
            {
                return(null);
            }

            IBinarySerializable obj = null;

            switch (classId)
            {
            case 0:
                break;

            default:
                throw new Exception(string.Format(Strings.ErrorBinarySerializerUnknownObjectType, classId));
            }
            obj.Deserialize(this);

            return(obj);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Reads and returns an object of the specified type from the current stream.
        /// </summary>
        /// <param name="type">Type of the object to read.</param>
        /// <returns>Object of the specified type read from the current stream.</returns>
        public object Deserialize(Type type)
        {
            // Check for primitive type.
            if (type.IsPrimitive())
            {
                return(this.DeserializePrimitive(type));
            }

            // Check for string.
            if (type == typeof(string))
            {
                return(this.reader.ReadString());
            }

            // Check for derived types.
            if (type == typeof(ValueWithType))
            {
                return(this.DeserializeValueWithType());
            }

            // Check for array.
            if (type.IsArray)
            {
                return(this.DeserializeArray());
            }

            // Check for list.
            if (typeof(IList).IsAssignableFrom(type))
            {
                return(this.DeserializeList());
            }

            // Check for dictionary.
            if (typeof(IDictionary).IsAssignableFrom(type))
            {
                return(this.DeserializeDictionary());
            }

            // Check for enum.
            if (type.IsEnum())
            {
                return(Enum.Parse(type, this.reader.ReadString()));
            }

            // Check for custom implementation.
            if (typeof(IBinarySerializable).IsAssignableFrom(type))
            {
                IBinarySerializable binarySerializable = (IBinarySerializable)Activator.CreateInstance(type);
                binarySerializable.Deserialize(this);
                return(binarySerializable);
            }

            // Deserialize with reflection.
            try
            {
                return(this.DeserializeReflection(type));
            }
            catch (Exception e)
            {
                throw new SerializationException(string.Format("Unsupported type: {0}", type.Name), e);
            }
        }
Ejemplo n.º 5
0
 public static void ReadInto(this BinaryReader reader, IBinarySerializable value)
 {
     value.Deserialize(reader);
 }