惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - zeus2

Xfire的初次使用 SQl Server 2012正式版发布 单例模式的三种实现方法 Oracle常用Hint Oracle 设计海量数据库 读书笔记(三) Oracle 设计海量数据库 读书笔记(二) Oracle 设计海量数据库 读书笔记(一) 解决中文ID3标签乱码zz 系统架构性能提高方案! 使用开源工具架设开发平台 修改SQL Server数据库地址 System.DateTimeOffset Load的问题 关于__doPostBack之前截获调用 - zeus2 - 博客园 当应用程序发布到iis7/iis7.5出现需要使用经典模式时 - zeus2 - 博客园 [读书笔记]SQL技术内幕Identity 根据实体类生成查询安全版 生活太艰难了。!!! 从底层角度看ASP.NET-A low-level Look at the ASP.NET Architecture(转载) C++访问Sqlite数据库(存档) - zeus2 - 博客园
XML序列化封装
zeus2 · 2009-06-27 · via 博客园 - zeus2

简单使用泛型封装下xml序列化

可以放到公共函数库

public class XmlSerialHelper

{

    /// <summary>

    /// 反序列化对象

    /// </summary>

    /// <typeparam name="T"></typeparam>

    /// <param name="path"></param>

    /// <returns></returns>

    public static T Deserialize<T>(string path)

    {

        XmlSerializer ser = new XmlSerializer(typeof(T));

        FileStream fs = new FileStream(path, FileMode.Open);

        T t = (T)ser.Deserialize(fs);

        fs.Close();

        return t;

    }

    /// <summary>

    /// 序列化对象

    /// </summary>

    /// <typeparam name="T">对象类型</typeparam>

    /// <param name="path">保存路径</param>

    /// <param name="t">对象实体</param>

    public static void Serialize<T>(string path, T t)

    {

        XmlSerializer ser = new XmlSerializer(typeof(T));

        FileStream fs = new FileStream(path, FileMode.OpenOrCreate);

        ser.Serialize(fs, t);

        fs.Close();

    }

}