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

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
J
Java Code Geeks
I
InfoQ
V
Visual Studio Blog
M
MIT News - Artificial intelligence
H
Help Net Security
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
G
Google Developers Blog
A
About on SuperTechFans
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
S
SegmentFault 最新的问题
WordPress大学
WordPress大学

博客园 - 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();
    }