1 序列化方法

        public void SerializeObject<T>(string Xmlname,T t)
{
XmlSerializer ser = new XmlSerializer(typeof(T)); TextWriter writer = new StreamWriter(Xmlname);
ser.Serialize(writer, t);//要序列化的对象
writer.Close();
}

2 序列化方法的使用

NodeConfigInfo nc = new NodeConfigInfo();
nc.FirstNodeSql = this.textBoxSqlFirstNode.Text.Trim();
nc.FirstArticleSql = this.textBoxViewFirArtlcle.Text.Trim();
nc.SecondNodeSql = this.textBoxSqlSecondNode.Text.Trim();
nc.SecondArticleSql = this.textBoxViewSecArtlcle.Text.Trim();
nc.SecondNodeFilter = this.textBoxSecFilter.Text.Trim();
nc.SecondArticleFilter = this.textBoxSecFilter.Text.Trim();
nc.SecondNodeDefaultParentId = this.textBoxParentDefault.Text.Trim();
nc.ConnectionOther = this.textBoxConnection.Text.Trim();
nc.NodeId = this.textBoxParentId.Text.Trim();
nc.SecondReFilter = this.textBoxReFilterSec.Text.Trim(); string xmlName = System.IO.Directory.GetCurrentDirectory() + "\\" + typeof(NodeConfigInfo).Name + ".Config";
SerializeObject<NodeConfigInfo>(xmlName, nc);

3 序列化的类

 public class NodeConfigInfo
{
public string FirstNodeSql { get; set; } public string FirstArticleSql { get; set; } public string SecondNodeSql { get; set; } public string SecondArticleSql { get; set; } public string SecondNodeFilter { get; set; } public string SecondArticleFilter { get; set; } public string SecondNodeDefaultParentId { get; set; } public string ConnectionOther { get; set; } public string NodeId { get; set; } public string SecondReFilter { get; set; }
}

4 反序列化方法

        public T DeSerializeObject<T>()
{
string xmlName = System.IO.Directory.GetCurrentDirectory() + "\\" + typeof(T).Name + ".Config";
FileStream file = new FileStream(xmlName, FileMode.Open, FileAccess.Read);
XmlSerializer xmlSearializer = new XmlSerializer(typeof(T));
T info = (T)xmlSearializer.Deserialize(file);
file.Close();
file.Dispose();
return info;
}

5 反序列化方法的使用

 //xml来源可能是外部文件,也可能是从其他系统获得
NodeConfigInfo info = DeSerializeObject<NodeConfigInfo>(); this.textBoxSqlFirstNode.Text = info.FirstNodeSql;
this.textBoxViewFirArtlcle.Text = info.FirstArticleSql;
this.textBoxSqlSecondNode.Text = info.SecondNodeSql;
this.textBoxViewSecArtlcle.Text = info.SecondArticleSql;
this.textBoxSecFilter.Text = info.SecondNodeFilter;
this.textBoxSecFilter.Text = info.SecondArticleFilter;
this.textBoxParentDefault.Text = info.SecondNodeDefaultParentId;
this.textBoxConnection.Text = info.ConnectionOther;
this.textBoxParentId.Text = info.NodeId;
this.textBoxReFilterSec.Text = info.SecondReFilter;

ASP.NET 对类进行XML序列化和反序列化的更多相关文章

  1. c# XML和实体类之间相互转换(序列化和反序列化)[砖]

    link: http://blog.okbase.net/haobao/archive/62.html by: 好饱 我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlU ...

  2. C# XML和实体类之间相互转换(序列化和反序列化)

    我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. using System; using System.Collections.Ge ...

  3. Xml序列化、反序列化帮助类

    之前从网络上找了一个Xml处理帮助类,并整理了一下,这个帮助类针对Object类型进行序列化和反序列化,而不需要提前定义Xml的结构,把它放在这儿供以后使用 /// <summary> / ...

  4. XML和实体类之间相互转换(序列化和反序列化)

    我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  5. .NET中XML序列化和反序列化常用类和用来控制XML序列化的属性总结(XmlSerializer,XmlTypeAttribute,XmlElementAttribute,XmlAttributeAttribute,XmlArrayAttribute...)

    序列化和反序列化是指什么? 序列化(seriallization): 将对象转化为便于传输的数据格式, 常见的序列化格式:二进制格式,字节数组,json字符串,xml字符串.反序列化(deserial ...

  6. 对类参数的序列化和反序列化XML

    /// <summary> /// Xml序列化与反序列化 /// </summary> public class XmlUtil { #region 反序列化 /// < ...

  7. Windows phone 之XML序列化与反序列化

    为什么要做序列化和反序列化? 一个回答: 我们都知道对象是不能在网络中直接传输的,不过还有补救的办法.XML(Extensible Markup Language)可扩展标记语言,本身就被设计用来存储 ...

  8. XML 序列化与反序列化

    XML序列化与反序列化 1.将一个类转化为XML文件 /// <summary> /// 对象序列化成XML文件 /// </summary> /// <param na ...

  9. XmlSerializer 对象的Xml序列化和反序列化

    http://www.cnblogs.com/yukaizhao/archive/2011/07/22/xml-serialization.html 这篇随笔对应的.Net命名空间是System.Xm ...

随机推荐

  1. Cesium原理篇:3D Tiles(1)渲染调度【转】

    Cesium在2016年3月份左右推出3D Tiles数据规范,在glTF基础上提供了LOD能力,定位就是Web环境下海量三维模型数据.虽然目前3D Tiles还是Beta阶段,有不少硬伤,但3D T ...

  2. Libnids(Library Network Intrusion Detection System) .

    Libnids(Library Network Intrusion Detection System)是一个网络入侵检测开发的专业编程接口.它实现了基于网络的入侵检测系统的基本框架,并提供了一些基本的 ...

  3. [leetcode]Merge Sorted Array @ Python

    原题地址:https://oj.leetcode.com/problems/merge-sorted-array/ 题意:Given two sorted integer arrays A and B ...

  4. Java系列:JVM中的OopMap(zz)

    调用栈里的引用类型数据是GC的根集合(root set)的重要组成部分:找出栈上的引用是GC的根枚举(root enumeration)中不可或缺的一环. JVM选择用什么方式会影响到GC的实现: 如 ...

  5. SharePoint 2016 IT Preview的新feature列表

    大致看了一下, 其中关于存储的部分貌似没有. 感觉Hybrid in SharePoint 2016未来可以做的事情比较多吧, 必须赶紧弄个cloud的东西开始玩玩了. Search的部署的更新, 以 ...

  6. html5各种页面切换效果和模态对话框

    页面动画:data-transition 属性可以定义页面切换是的动画效果.例如:<a href="index.html" data-transition="pop ...

  7. 初学 Delphi 嵌入汇编[1] - 汇编语言与机器语言

    非科班出身, 现在才接触汇编, 惭愧呀, 好好学! 主选课本是清华大学王爽老师的<汇编语言>. 推荐 王爽老师的汇编网 汇编语言之前是机器语言. 机器语言是机器指令的集合, 机器指令是一系 ...

  8. Datetimepicker配置参数

    jquery的datetimepicker时间控件除了样式有点不太美观,功能性还是相当强大的. 在正常情况下input的type应该设置为"text",可点击又可输入(mask,e ...

  9. ifdef ANDROID总是不好用

    在vs的proprocessor definition中定义了ANDRIOD, 但是执行下面的代码的时候,总是说ANDROID is not defined.     #ifdef ANDROID   ...

  10. 异步 JS: Callbacks, Listeners, Control Flow Libs 和 Promises【转载+翻译+整理】

    http://sporto.github.io/blog/2012/12/09/callbacks-listeners-promises/ 或 http://www.ruanyifeng.com/bl ...