zoukankan      html  css  js  c++  java
  • C# XmlSerializer实现序列化浅析(转载)

    • C# XmlSerializer实现序列化浅析

     

      C# XmlSerializer类是实现序列化的一个类,那么关于C# XmlSerializer的学习我们要掌握怎么样的操作方法呢?那么这里向你详细介绍具体的操作细节情况。

      C# XmlSerializer是什么呢?它是使用二进制格式化程序进行序列化的一个类,那么具体的通过C# XmlSerializer如何实现序列化操作呢?在序列化操作的过程中需要注意些什么呢?

      C# XmlSerializer的出处:

      1. using System.Xml.Serialization; 

      C# XmlSerializer实现序列化:

      1. XmlSerializer xml = new XmlSerializer(typeof(Test));  
      2. FileStream fs = new FileStream(@"c:\t.xml",FileMode.Create);  
      3. xml.Serialize(fs, t);  
      4. fs.Close(); 

      C# XmlSerializer实现反序列化

      1. FileStream fs = new FileStream(@"c:\t.xml", FileMode.Open);  
      2. XmlSerializer xml = new XmlSerializer(typeof(Test));  
      3. Test t = (Test)xml.Deserialize(fs); 

      C# XmlSerializer类与主流的序列化类的几个不同点是:

      1、不需要Serializable属性,Serializable和NonSerializable属性将会被忽略,但是使用XmlIgnore属性,和NonSerializable属性类似。

      2、该类不能安全地访问私有变成员,所以学要将私有成员改为公共成员,或者提供合适的公共特性。

      3、要求被序列化的类要有一个默认的构造器。

      C# XmlSerializer的使用基本情况就向你介绍到这里,希望对你了解和学习C# XmlSerializer类有所帮助,并且对序列化的操作有所认识。

      转载自:http://developer.51cto.com/art/200909/150786.htm

      Object serialization is an important topic which is quite powerful if used correctly. Serialization allows programms to persist objects by storing then in files. In the case of this tutorial, into XML files. XML has become the standard for storage in the recent years and its good to see that with XML serialization built into the .NET framework, it will be very simple to build applications which can interop well with any other software, Microsoft or not.
      This tutorial assumes a basic knowledge of programming. One thing that people may not be familiar with is the concept of attributes which is used heavily in this tutorial。

      So there you have it. XML Serialization in C#. This is an incredibly useful way for application developers to persist objects by storing them in a file. It makes it really simple for any programmer to save configuration settings into XML files or application documents as well.

      From:http://devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=236

  • 相关阅读:
    2017 业余程序员的回顾
    而立将近,可有不惑
    谈谈转行
    吃干抹净提上裤子就甩
    Autosizer应用程序窗口控制工具
    AutoCAD2007专业版
    Revit中如何添加水平仰视平面视图
    Revit中绘制带坡度管道
    Revit自定义快递访问工具栏
    Revit利用对正工具快速修改风管对齐方式
  • 原文地址:https://www.cnblogs.com/wuhenke/p/1621437.html
Copyright © 2011-2022 走看看