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



  • 相关阅读:
    tensorflow2.0——简单的三种图像增强方式(翻转,光照,对比度)
    tensorflow2.0——卷积初始化
    tensorflow2.0——实现先卷积后LSTM的网络
    tensorflow2.0——compile-fit实现多输入复合模型
    CMDB-客户端
    saltstack部署
    CMDB实现的四种方式
    理解python中的元类
    RESTful 架构
    Vuex笔记/axios笔记
  • 原文地址:https://www.cnblogs.com/lexus/p/1707034.html
Copyright © 2011-2022 走看看