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

推荐订阅源

量子位
Vercel News
Vercel News
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
N
Netflix TechBlog - Medium
Google DeepMind News
Google DeepMind News
H
Help Net Security
罗磊的独立博客
The Cloudflare Blog
J
Java Code Geeks
博客园 - 叶小钗
I
InfoQ
B
Blog
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
月光博客
月光博客
博客园_首页
雷峰网
雷峰网
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
美团技术团队
T
The Blog of Author Tim Ferriss
博客园 - 司徒正美

博客园 - moge

新建的网站 八方达物流网 How to Implement an Automatic Sliding Window in a Partitioned Table on SQL Server 2005 SQL Server 2005 Partitioned Tables and Indexes 如何估算数据库的大小 MSDN链接 Enabling Change Data Capture SQL Server 操作集锦 转一篇很经典的房价文章 在SharePoint中激活Page Library功能 Database Coding Standard and Guideline 计算机电子书免费下载列表 3 计算机电子书免费下载列表 2 计算机免费电子书下载 1 国外可以赚钱的免费硬盘 推荐一个下载电子书的网站 不需要注册 Javascript中的apply和call函数 ASP.NET AJAX客户端生命周期分析(实践篇)(2) 101个设计模式 Design Patterns 用C#操作Person or Group列在SharePoint中
继承CollectionBase的类的xml序列化
moge · 2009-03-01 · via 博客园 - moge

看代码:

XML文件
<ArrayOfDepartment>
<Department>
<name>研发中心</name> 
</Department>
<Department>
<name>营销中心</name> 
</Department> 
</ArrayOfDepartment>

[Serializable]
  
public   class   Department
    {
   
public   Department()
    
{
   }
 
   
private   string   _name;
   
public   string   name
    
{
    
get 
      
{
     
return   this ._name;
    }
 
    
set 
      
{
     
this ._name = value;
    }
 
   }
 
 }
 
 
[Serializable]
 
public   class   DepartmentCollection:CollectionBase
   

   
   
public   DepartmentCollection()
    
{
    
// 
    
//   TODO: 在此处添加构造函数逻辑
    
//     
    }
    
   
public   Department  this [ int   index] 
    
{
    
get    return   ((Department)( this .List[index]));} 
   }
 
 
   
public   int   Add(Department dp) 
    
{   
    
return   List.Add(dp) ;
   }
 
 }
 
 
 
public   static   object   Load(Type type,  string   filename)
    
{
    FileStream fs  
=   null ;
    
try 
      
{
     
//   open the stream 
      fs  =   new   FileStream(filename, FileMode.Open,FileAccess.Read);
     XmlSerializer serializer  
=   new   XmlSerializer(type);
     
return   serializer.Deserialize(fs);
    }
 
    
catch (Exception e)
     
{
     
throw   e;
    }
 
    
finally 
      
{
     
if (fs  !=   null )
      fs.Close();
    }