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

  • 相关阅读:
    IE8及其以下浏览器边框圆角兼容问题
    关于git的一些指令及遇到的问题和解决方法
    vue项目环境搭建及运行
    webpack中的重要功能
    webpack 的重要功能
    c++ stl sort 自定义排序函数cmp要遵循 strict weak ordering
    spring boot 包jar运行
    windows上传文件到linux云服务器上
    最少硬币数目的问题
    leetcode 415 两个字符串相加
  • 原文地址:https://www.cnblogs.com/wuhenke/p/1621437.html
Copyright © 2011-2022 走看看