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

推荐订阅源

D
Docker
IT之家
IT之家
Microsoft Security Blog
Microsoft Security Blog
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
DataBreaches.Net
B
Blog RSS Feed
博客园_首页
The GitHub Blog
The GitHub Blog
I
InfoQ
L
LangChain Blog
G
Google Developers Blog
M
MIT News - Artificial intelligence
美团技术团队
腾讯CDC
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗

博客园 - 吴勇

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
    }