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



  • 相关阅读:
    如何设置项目encoding为utf-8
    如何使用Navicat恢复数据库脚本
    如何使用Navicat备份数据库脚本
    表单编辑组件使用指南
    Maven如何打包本地依赖包
    怎么替换jar包里面的文件?
    如何开始创建第一个基于Spring MVC的Controller
    怎么将数据库从Oracle迁移到SQL Server,或从Oracle迁移到MySQL
    如何使用Eclipse调试framework
    windows下安装oracle,sqlplus连接启动oracle(oracle 主机字符串输入是什么)
  • 原文地址:https://www.cnblogs.com/lexus/p/1707034.html
Copyright © 2011-2022 走看看