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

推荐订阅源

I
InfoQ
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
月光博客
月光博客
博客园 - 聂微东
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
S
SegmentFault 最新的问题
F
Fortinet All Blogs
H
Help Net Security
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
L
LangChain Blog
Martin Fowler
Martin Fowler
N
Netflix TechBlog - Medium

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