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



  • 相关阅读:
    致21岁的自己
    nginx 入门实战
    软件测试的分类
    Springboot 使用 Jedis
    NodeJS模块、包、NPM
    NodeJS介绍
    毫秒必争,前端网页性能最佳实践--转载
    IT主要在线学习网站
    电商峰值系统架构设计--转载
    查看w3wp进程占用的内存及.NET内存泄露,死锁分析--转载
  • 原文地址:https://www.cnblogs.com/lexus/p/1707034.html
Copyright © 2011-2022 走看看