Exemplo n.º 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();
 }
Exemplo n.º 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();
 }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
 }
Exemplo n.º 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();
 }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }