Пример #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            string             str  = "<row>0123456789zbcdefghij0123456789zbcdefghij0123456789zbcdefghij0123456789zbcdefghij0123456789zbcdefghij0123456789zbcdefghij0123456789zbcdefghij0123456789zbcdefghij0123456789zbcdefghij0123456789zbcdefghij</row>";
            FileBufferedStream fstr = new FileBufferedStream();

            fstr.Append("<rows>");
            int i = 0;

            while (i < 100)
            {
                i++;
                fstr.Append(str);
            }
            fstr.Append("</rows>");

            Class1 c1 = new Class1();

            c1.age     = 20;
            c1.name    = "anme";
            c1.content = fstr;

            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter serializer =
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            FileStream stream = new FileStream(@"e:\1.tmp", FileMode.CreateNew, FileAccess.ReadWrite);

            serializer.Serialize(stream, c1);
            stream.Close();

            FileStream stream2 = new FileStream(@"e:\1.tmp", FileMode.Open, FileAccess.ReadWrite);
            Class1     c12     = serializer.Deserialize(stream2) as Class1;

            richTextBox1.Text = c12.age + "," + c12.name + "," + c12.content.Length;

            //XmlElement node = ObjectSerializeHelper.Deserialize<XmlElement>("<row>ddddd</row>");
            //MessageBox.Show("name:" + node.LastChild.Name);

            byte[]       bytes = Encoding.UTF8.GetBytes(str);
            MemoryStream ms    = new MemoryStream();

            ms.Write(bytes, 0, bytes.Length);
            //MemoryStream ms = new MemoryStream(bytes);
            //ms.Write(bytes, 0, bytes.Length);
            fstr.Seek(0, SeekOrigin.Begin);
            //StreamReader sr = new StreamReader(ms, encoding: Encoding.UTF8);
            //string str2 = Encoding.UTF8.GetString(ms.ToArray());
            //TextReader tr = new StringReader(str2);

            XmlElement node = Deserialize <XmlElement>(fstr);

            fstr.Dispose();
            //XmlElement node = Deserialize<XmlElement>(fstr.GetStream());
            //XmlElement node = ObjectSerializeHelper.Deserialize<XmlElement>(str2);
            MessageBox.Show("name:" + node.LastChild.Name);
            Stream ss = SerializeToString <XmlElement>(node);

            ss.Seek(0, SeekOrigin.Begin);
            XmlElement nd = Deserialize <XmlElement>(ss);

            MessageBox.Show("name2:" + nd.LastChild.Name);
            ss.Dispose();
        }