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

推荐订阅源

爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
Martin Fowler
Martin Fowler
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
U
Unit 42
B
Blog RSS Feed
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
腾讯CDC
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
博客园 - 聂微东
MyScale Blog
MyScale Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta

博客园 - 吴勇

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
    }