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. iOS开发-UITextView实现PlaceHolder的方式

    之前开发遇到过UITextField中加入一个PlaceHolder的问题,直接设置一下即可,不过这次是需要在UITextView中实现一个PlaceHolder,跟之前有点不同.在网上参考了各位前辈 ...

  2. Add Binary Leetcode java

    题目: Given two binary strings, return their sum (also a binary string). For example, a = "11&quo ...

  3. 【math】梯度下降法(梯度下降法,牛顿法,高斯牛顿法,Levenberg-Marquardt算法)

    原文:http://blog.csdn.net/dsbatigol/article/details/12448627 何为梯度? 一般解释: f(x)在x0的梯度:就是f(x)变化最快的方向 举个例子 ...

  4. oracle v$sqlarea 分析SQL语句使用资源情况 确认是否绑定变量

    -如何确定系统中是否存在绑定变量的情况:首先创建一个表,用于存放整理过得数据:create table t1 as select sql_text from v$sqlarea;----V$SQLAR ...

  5. ArcMap工具箱参数名称的Bug

    已经忍了很久了,今天一定要说一说,强大的 ArcGIS居然还存在这种Bug问题.如下图所示:使用了追加工具,有三个要素图层,且三个数据与目标数据不是同一数据,但它们的名称一致,这样执行,将会出现&qu ...

  6. android中RecyclerView控件实现点击事件

    RecyclerView控件实现点击事件跟ListView控件不同,并没有提供类似setOnItemClickListener()这样的注册监听器方法,而是需要自己给子项具体的注册点击事件. 本文的例 ...

  7. 从C# 2.0新特性到C# 3.5新特性

    一.C# 2.0 新特性: 1.泛型 List<MyObject> obj_list=new List(); obj_list.Add(new MyObject()); 2.部分类(par ...

  8. Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&加载插件

    本文主要记录下在使用selenium2/webdriver时启动各种浏览器的方法.以及如何加载插件.定制浏览器信息(设置profile)等 环境搭建可参考我的另一篇文章:http://www.cnbl ...

  9. 忘记webogic管理控制台密码

    cd /user_projects/domains/base_domain/security cp DefaultAuthenticatorInit.ldift DefaultAuthenticato ...

  10. POSTGRESQL 支持正则表达式

    昨天遇到了一个奇葩的问题,需要在WHERE条件里面添加正则表达式,抱着试试看的态度,查看了一下postgresql,发现确实可以支持正则,例如: select * from user where em ...