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



  • 相关阅读:
    表观遗传学|
    Mutation|DNM|
    Right journal|First-class paper|Mediocre paper|figure legend |Discussion|Introduction
    PCoA|NMDS|STRESS|RDA |RA|Unimodal|CCA|Generalized Joint Attribute Modeling
    缺失值|回归分析|协变关系|
    基金写作流程|留学回国人员启动资金
    nexage video asset tag
    获取的时候报cannot find package "golang.org /x/net/context",编译也报错误
    google play apk 下载
    vim golang 插件
  • 原文地址:https://www.cnblogs.com/lexus/p/1707034.html
Copyright © 2011-2022 走看看