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

推荐订阅源

爱范儿
爱范儿
H
Help Net Security
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
博客园 - 叶小钗
Y
Y Combinator Blog
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
C
Check Point Blog
Recent Announcements
Recent Announcements
IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
B
Blog

博客园 - 吴勇

windbg入门 wpf数据显示控件 - 吴勇 - 博客园 Enterprise Library 快速入门3(Exception Handling Application Block) 操作系统方法 复合宾语和双宾语 句子 操作流 高级sql查询 反射技术 使用游标 基于.net开发平台项目案例集锦 设计原则 常用工具下载地址 反射 简单代码 微软正式推出.NET Framework 3.0 Redistributable Package 核心用户控件 Visual C# 3.0 新特性概览 文件夹压缩代码
序列化
吴勇 · 2006-12-31 · via 博客园 - 吴勇

格式化程序是一个知道如何将任何对象写到一个流中的对象。IFormatter

using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Formatters.Soap;

IFormatter formatter 
= new SoapFormatter();

完整代码

    [SerializableAttribute]
    
public class TestClass:IDeserializationCallback,ISerializable
    
{
        [NonSerializedAttribute]
        
public string aa;     //不可序列化的字段
        public string mystring;
        
string s = "Wahoo!";
        
int n = 6;
        ArrayList oldStrings
=new ArrayList();
        
static string currentVersion="2.0";
        
public TestClass(SerializationInfo info, StreamingContext context)
        
{
            
//mystring = info.GetString("MyString");
            mystring = (string)info.GetValue("MyString"typeof(string));
            
string streamVersion=info.GetString("Version");
            
switch(streamVersion)
            
{
                
case "1.0":
                    s
=info.GetString("MyString");
                    n
=s.Length;
                    
break;
                
case "2.0":
                    s
=info.GetString("MyString");
                    n
=s.Length;
                    oldStrings
=(ArrayList)info.GetValue("OldStrings",typeof(ArrayList));
                    
break;
                
default:
                    
string message=string.Format("Version{0} is not supported.",streamVersion);
                    
throw new SerializationException(message);
                    
            }

        }

        
IDeserializationCallback Members

        
ISerializable Members
    }