浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

和同事在linqpad的帮助下讨论了一下,能不能序化传递函数,

经测试,内置的binaryformatter是可以的,xmlserializer是不行的,

另外知道了Type是抽象类,System.RuntimeType是其实现,A的实例a的GetType是a,a再GetType是runtimetype

void Main()
{
    
using(MemoryStream ms = new MemoryStream()){
    BinaryFormatter bf =
new BinaryFormatter();
    bf.Serialize(ms,
typeof(A));
    bf.Dump();
    ms.Length.Dump();
    }
    
    
using(MemoryStream ms = new MemoryStream()){
        
var x = typeof(A);
        
var xmlf = new XmlSerializer(x.GetType());
        xmlf.Serialize(ms, x);
    
    
//        var xmlf = new XmlSerializer(typeof(A));
//        xmlf.Serialize(ms, new A());
    }
}

public class A{
    
public int I {get; set;}
}

// Define other methods and classes here

void Main()
{
    
using(MemoryStream ms = new MemoryStream()){
    BinaryFormatter bf =
new BinaryFormatter();
    bf.Serialize(ms,
typeof(A));
    bf.Dump();
    ms.Length.Dump();
    }
    
    
using(MemoryStream ms = new MemoryStream()){
        
var x = typeof(A);
        
var xmlf = new XmlSerializer(x.GetType());
        xmlf.Serialize(ms, x);
    
    
//        var xmlf = new XmlSerializer(typeof(A));
//        xmlf.Serialize(ms, new A());
    }
}

public class A{
    
public int I {get; set;}
}

// Define other methods and classes here



posted on 2010-04-08 10:28  lexus  阅读(173)  评论(0编辑  收藏  举报