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
        /// <summary>Marshals data to a stream</summary>
        /// <param name="o">object to marshal</param>
        /// <param name="stream">stream to marshal the data to</param>
        static public void Serialize(object o, Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            BinarySerializer.SerializeFields(writer, o);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        static private void InternalSerializeInstance(BinaryWriter writer, object o, Type t)
        {
            if (t == typeof(Boolean))
            {
                writer.Write(( Boolean )o);
                return;
            }

            if (t == typeof(Char))
            {
                writer.Write(( Char )o);
                return;
            }

            if (t == typeof(SByte))
            {
                writer.Write(( SByte )o);
                return;
            }

            if (t == typeof(Byte))
            {
                writer.Write(( Byte )o);
                return;
            }

            if (t == typeof(Int16))
            {
                writer.Write(( Int16 )o);
                return;
            }

            if (t == typeof(UInt16))
            {
                writer.Write(( UInt16 )o);
                return;
            }

            if (t == typeof(Int32))
            {
                writer.Write(( Int32 )o);
                return;
            }

            if (t == typeof(UInt32))
            {
                writer.Write(( UInt32 )o);
                return;
            }

            if (t == typeof(Int64))
            {
                writer.Write(( Int64 )o);
                return;
            }

            if (t == typeof(UInt64))
            {
                writer.Write(( UInt64 )o);
                return;
            }

            //if (t == typeof(Single))
            //{
            //    writer.Write((Single)o);
            //    return;
            //}

            //if (t == typeof(Double))
            //{
            //    writer.Writer((Double)o);
            //    return;
            //}

            if (t == typeof(String))
            {
                if (o == null)
                {
                    writer.Write(string.Empty);
                }
                else
                {
                    writer.Write(( String )o);
                }

                return;
            }

            // 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", "o");
            }

            BinarySerializer.InternalSerializeFields(writer, o, t);
        }
Exemplo n.º 5
0
        /// <summary>Unmarshals a data object from a byte array</summary>
        /// <param name="o">Object to unmarshal the byte array into</param>
        /// <param name="buf">byte array containing Marshalled data to unmarshal</param>
        static public void DeSerialize(object o, byte[] buf)
        {
            MemoryStream stream = new MemoryStream((buf != null) ? buf : new byte[1]);

            BinarySerializer.DeSerialize(o, stream);
        }