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. SVN详细配置与使用 ——一步步教会您使用

    项目管理在项目开发活动中起到非常重要的作用,而对于初学者来说学习有一定的难度,且不说如何使用,就是搭建过程恐怕也要费一般周折,介于此下面就通过图解的方式一步一步详细的教大家如何使用SVN,你只要耐心的 ...

  2. 八一八android开发规范(一种建议)

    开发规范重不重要了,不言而喻.这里就给大家说一故事把——据<圣经·旧约·创世记>第11章记载,是当时人类联合起来兴建,希望能通往天堂的高塔.为了阻止人类的计划,上帝让人类说不同的语言,使人 ...

  3. LDA(latent dirichlet allocation)的应用

    http://www.52ml.net/1917.html 主题模型LDA(latent dirichlet allocation)的应用还是很广泛的,之前我自己在检索.图像分类.文本分类.用户评论的 ...

  4. 平均值(Mean)、方差(Variance)、标准差(Standard Deviation) (转)

    http://blog.csdn.net/xidiancoder/article/details/71341345 平均值 平均值的概念很简单:所有数据之和除以数据点的个数,以此表示数据集的平均大小: ...

  5. Setting a maximum attachment size

      By default IBM® Lotus® iNotes™ allows a maximum attachment size of 50,000K (50MB). You can increas ...

  6. [Algorithm] Reservoir Sampling

    Given a stream of elements too large to store in memory, pick a random element from the stream with ...

  7. 机器学习之深入理解SVM

    在浏览本篇博客之前,最好先查看一下我写的还有一篇文章机器学习之初识SVM(点击可查阅哦).这样能够更好地为了结以下内容做铺垫! 支持向量机学习方法包括构建由简至繁的模型:线性可分支持向量机.线性支持向 ...

  8. 通读Cheerio文档

    前言 cheerio是一款非常实用的nodejs第三方包,适用于服务端(nodejs端)处理html.它有着与jquery及其相似(几乎是一致)的api,速度飞快,使用灵活,而且不仅能够处理html, ...

  9. Mybatis特殊值Enum类型转换器-ValuedEnumTypeHandler

    引言 typeHandlers 阅读官方文档 typeHandlers 一节 {:target="_blank"} MyBatis 在预处理语句(PreparedStatement ...

  10. centos7默认安装没有连接到网络

    1.显示所有连接 # nmcli con show 2.连接到网络 # nmcli con up enp0s3 这个ens33是通过显示所有连接查到的