Exemplo n.º 1
0
        static private void SerializeFields(BinaryWriter reader, object o)
        {
            Type t = o.GetType();

            if (t.IsArray)
            {
                BinarySerializer.InternalSerializeInstance(reader, o, t);
            }
            else
            {
                BinarySerializer.InternalSerializeFields(reader, o, t);
            }
        }
Exemplo n.º 2
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);
        }