zoukankan      html  css  js  c++  java
  • 关于.net平台序列化函数相关的问题

    和同事在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



  • 相关阅读:
    the error about “no such file or directory”
    Unable to Distribute in Xcode5?
    第一次连接数据库mongodb踩的坑
    在Mac下安装mongodb
    sudo brew install mongodb报错
    nodemon 热更新
    npm install 之前做的事
    JS事件委托应用场景
    解决CDN传统方法引入Iview icon 不显示问题
    React 入门
  • 原文地址:https://www.cnblogs.com/lexus/p/1707034.html
Copyright © 2011-2022 走看看