Пример #1
0
 /// <summary>
 /// XML序列化
 /// </summary>
 public void XMLSerialize()
 {
     ClassToSerialize c = new ClassToSerialize();
     XmlSerializer mySerializer = new XmlSerializer(typeof(ClassToSerialize));
     StreamWriter myWriter = new StreamWriter(this.txtFilePath.Text + "Serialize.xml");
     mySerializer.Serialize(myWriter, c);
     myWriter.Close();
 }
Пример #2
0
 /// <summary>
 /// 二进制序列化
 /// </summary>
 public void BinarySerialize()
 {
     ClassToSerialize c = new ClassToSerialize();
     FileStream fileStream = new FileStream(this.txtFilePath.Text + "Serialize", FileMode.Create);
     BinaryFormatter b = new BinaryFormatter();
     b.Serialize(fileStream, c);
     fileStream.Close();
 }
Пример #3
0
        /// <summary>
        /// XML序列化
        /// </summary>
        public void XMLSerialize()
        {
            ClassToSerialize c            = new ClassToSerialize();
            XmlSerializer    mySerializer = new XmlSerializer(typeof(ClassToSerialize));
            StreamWriter     myWriter     = new StreamWriter(this.txtFilePath.Text + "Serialize.xml");

            mySerializer.Serialize(myWriter, c);
            myWriter.Close();
        }
Пример #4
0
        /// <summary>
        /// 二进制序列化
        /// </summary>
        public void BinarySerialize()
        {
            ClassToSerialize c          = new ClassToSerialize();
            FileStream       fileStream = new FileStream(this.txtFilePath.Text + "Serialize", FileMode.Create);
            BinaryFormatter  b          = new BinaryFormatter();

            b.Serialize(fileStream, c);
            fileStream.Close();
        }
Пример #5
0
 /// <summary>
 /// 反序列化
 /// </summary>
 public void XMLDeserialize()
 {
     ClassToSerialize c = new ClassToSerialize();
     c.sex = "man";
     c.MoblieNumber = "15818526539";
     XmlSerializer mySerializer = new XmlSerializer(typeof(ClassToSerialize));
     FileStream myFileStream = new FileStream(this.txtFilePath.Text + "Serialize.xml", FileMode.Open);
     c = mySerializer.Deserialize(myFileStream) as ClassToSerialize;
     this.lbResult.Text = "【Name】" + c.name + " 【Sex】" + c.sex + " 【MoblieNumber】" + c.MoblieNumber;
     myFileStream.Close();
 }
Пример #6
0
 /// <summary>
 /// 反序列化
 /// </summary>
 public void BinaryDeserialize()
 {
     ClassToSerialize c = new ClassToSerialize();
     c.sex = "女";
     c.MoblieNumber = "15818526539";
     FileStream fileStream = new FileStream(this.txtFilePath.Text + "Serialize", FileMode.Open, FileAccess.Read, FileShare.Read);
     BinaryFormatter b = new BinaryFormatter();
     c = b.Deserialize(fileStream) as ClassToSerialize;
     this.lbResult.Text = "【Name】" + c.name + " 【Sex】" + c.sex + " 【MoblieNumber】" + c.MoblieNumber;
     fileStream.Close();
 }
Пример #7
0
        /// <summary>
        /// 反序列化
        /// </summary>
        public void XMLDeserialize()
        {
            ClassToSerialize c = new ClassToSerialize();

            c.sex          = "man";
            c.MoblieNumber = "15818526539";
            XmlSerializer mySerializer = new XmlSerializer(typeof(ClassToSerialize));
            FileStream    myFileStream = new FileStream(this.txtFilePath.Text + "Serialize.xml", FileMode.Open);

            c = mySerializer.Deserialize(myFileStream) as ClassToSerialize;
            this.lbResult.Text = "【Name】" + c.name + " 【Sex】" + c.sex + " 【MoblieNumber】" + c.MoblieNumber;
            myFileStream.Close();
        }
Пример #8
0
        /// <summary>
        /// 反序列化
        /// </summary>
        public void BinaryDeserialize()
        {
            ClassToSerialize c = new ClassToSerialize();

            c.sex          = "女";
            c.MoblieNumber = "15818526539";
            FileStream      fileStream = new FileStream(this.txtFilePath.Text + "Serialize", FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryFormatter b          = new BinaryFormatter();

            c = b.Deserialize(fileStream) as ClassToSerialize;
            this.lbResult.Text = "【Name】" + c.name + " 【Sex】" + c.sex + " 【MoblieNumber】" + c.MoblieNumber;
            fileStream.Close();
        }