Exemplo n.º 1
0
        /// <summary>Unmarshals data from the given stream</summary>
        /// <param name="o">object to unmarshal into</param>
        /// <param name="stream">stream to unmarshal data from</param>
        static public void DeSerialize(object o, Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            BinarySerializer.DeserializeFields(reader, o);
        }
Exemplo n.º 2
0
        static private object InternalDeserializeInstance(BinaryReader reader, object o, Type t)
        {
            if (o != null)
            {
                t = o.GetType( );
            }

            if (o != null && (o.GetType( ) != t))
            {
                throw new ArgumentException("type 't' doesn't match provided object 'o'");
            }

            if (t == typeof(Boolean))
            {
                return(reader.ReadBoolean( ));
            }

            if (t == typeof(Char))
            {
                return(reader.ReadChar( ));
            }

            if (t == typeof(SByte))
            {
                return(reader.ReadSByte( ));
            }

            if (t == typeof(Byte))
            {
                return(reader.ReadByte( ));
            }

            if (t == typeof(Int16))
            {
                return(reader.ReadInt16( ));
            }

            if (t == typeof(UInt16))
            {
                return(reader.ReadUInt16( ));
            }

            if (t == typeof(Int32))
            {
                return(reader.ReadInt32( ));
            }

            if (t == typeof(UInt32))
            {
                return(reader.ReadUInt32( ));
            }

            if (t == typeof(Int64))
            {
                return(reader.ReadInt64( ));
            }

            if (t == typeof(UInt64))
            {
                return(reader.ReadUInt64( ));
            }
            //
            //        if(t==typeof(Single))
            //            return reader.ReadSingle();
            //
            //        if(t==typeof(Double))
            //            return reader.ReadDouble();

            if (t == typeof(String))
            {
                return(reader.ReadString( ));
            }

            // arrays introduce too many complications to support at this time
            // far to many border or special case considerations need to be accounted
            // for; the entire implementation of this class needs a re-design to
            // do that adequately.
            if (t.IsArray)
            {
                throw new ArgumentException("Arrays are not supported for serialization");
            }

            if (!t.IsValueType && !t.IsClass)
            {
                throw new ArgumentException("unsupported type for parameter 'o'");
            }

            BinarySerializer.DeserializeFields(reader, o);
            return(o);
        }