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

推荐订阅源

C
Cyber Attacks, Cyber Crime and Cyber Security
The Last Watchdog
The Last Watchdog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
W
WeLiveSecurity
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
News | PayPal Newsroom
D
DataBreaches.Net
博客园_首页
Y
Y Combinator Blog
F
Fortinet All Blogs
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
B
Blog RSS Feed
C
CERT Recently Published Vulnerability Notes
P
Privacy & Cybersecurity Law Blog
Help Net Security
Help Net Security
S
SegmentFault 最新的问题
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
News and Events Feed by Topic
Schneier on Security
Schneier on Security
V
Vulnerabilities – Threatpost
A
About on SuperTechFans
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
L
LINUX DO - 热门话题
Simon Willison's Weblog
Simon Willison's Weblog
雷峰网
雷峰网
G
Google Developers Blog
Cyberwarzone
Cyberwarzone
I
Intezer
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
C
Check Point Blog
AI
AI
博客园 - 【当耐特】
有赞技术团队
有赞技术团队
博客园 - 司徒正美

博客园 - 情走边锋

(摘)设置FCKeditor回车换行方式 JBossESB问题记录 jstl fmt功能说明 oracle中number类型说明 解决通过createElement创建出来的radio无法选中的问题 asp.net C# 中使用timestamp 编码 GBK 的不可映射字符 解决办法 asp.net中SQL注入的解决办法 - 情走边锋 - 博客园 SQL2005部署报表:用户IUSER_ 授予的权限不足的问题 发现一个网页幻灯制作的东西HTML Slidy AS无法连接,由于目标机积极拒绝,无法连接。127.0.0.1:2382(system) Android中ActivityManager: Error: Activity class {XXX} does not exist的问题 windows上安装postgresql OpenBSD4.0下安装samba IE6无法正常显示VML Linux下Makefile的automake生成全攻略 随记 C++中的头文件 开始Bro之旅
序列化与反序列化
情走边锋 · 2007-06-11 · via 博客园 - 情走边锋

在discuz NT中看到的
xml与object之间的序列化与反序列化

        /// <summary>
        
/// 反序列化
        
/// </summary>
        
/// <param name="type">对象类型</param>
        
/// <param name="filename">文件路径</param>
        
/// <returns></returns>

        public static object Load(Type type, string filename)
        
{
            FileStream fs 
= null;
            
try
            
{
                
// open the stream
                fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                XmlSerializer serializer 
= new XmlSerializer(type);
                
return serializer.Deserialize(fs);
            }

            
catch(Exception ex)
            
{
                
throw ex;
            }

            
finally
            
{
                
if(fs != null)
                    fs.Close();
            }

        }



        
/// <summary>
        
/// 序列化
        
/// </summary>
        
/// <param name="obj">对象</param>
        
/// <param name="filename">文件路径</param>

        public static void Save(object obj, string filename)
        
{
            FileStream fs 
= null;
            
// serialize it
            try
            
{
                fs 
= new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                XmlSerializer serializer 
= new XmlSerializer(obj.GetType());
                serializer.Serialize(fs, obj);    
            }

            
catch(Exception ex)
            
{
                
throw ex;
            }

            
finally
            
{
                
if(fs != null)
                    fs.Close();
            }


        }