和同事在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
{
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
![](http://img.zemanta.com/pixy.gif?x-id=28a5e4ec-70b1-8d35-8b35-d0166cfd4947)