`
mlzboy
  • 浏览: 703110 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

关于.net平台序列化函数相关的问题

阅读更多
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"> <link rel="themeData" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"> <link rel="colorSchemeMapping" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml"> <!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><xml> </xml><![endif]--><style> <!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:Consolas; panose-1:2 11 6 9 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-1610611985 1073750091 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:widow-orphan; font-size:10.5pt; font-family:"Calibri","sans-serif"; mso-fareast-font-family:宋体; mso-bidi-font-family:宋体;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} </style> <![endif]-->

和同事在linqpad的帮助下讨论了一下,能不能序化传递函数,

经测试,内置的binaryformatter是可以的,xmlserializer是不行的,

<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"><link rel="themeData" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"><link rel="colorSchemeMapping" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml"><!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><xml> </xml><![endif]--><style> <!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:Consolas; panose-1:2 11 6 9 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-1610611985 1073750091 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:widow-orphan; font-size:10.5pt; font-family:"Calibri","sans-serif"; mso-fareast-font-family:宋体; mso-bidi-font-family:宋体;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} </style> <![endif]-->

另外知道了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



分享到:
评论

相关推荐

    深入.Net平台和C#编程

    深入.Net平台和C#编程 值类型和引用类型 集合操作 类、对象、构造函数、方法重载、静态方法、对象交互 面向对象特性:继承、多态 虚方法 方法重写 抽象类 设计模式 TreeView 控件 XML解析 读写文本文件 文件和文件夹...

    asp.net知识库

    泛型的序列化问题 .NET 2.0 泛型在实际开发中的一次小应用 C#2.0 Singleton 的实现 .Net Framwork 强类型设计实践 通过反射调用類的方法,屬性,字段,索引器(2種方法) ASP.NET: State Server Gems 完整的动态加载/卸载...

    PolySerializer:一个通用的.NET序列化程序,用于程序集之间的对象交换。 支持多态性以及更多

    多态序列化器一个通用的.NET序列化程序,用于程序集之间的对象交换。 支持多态性等等。 PolySerializer接受C#对象并对其进行序列化(即,将它们复制到可以存档或交换的流中)。 与大多数序列化程序相反,它将在支持...

    GadgetTo[removed]用于生成 .NET 序列化小工具的工具,当使用来自基于 JSVBSVBA 的脚本的 BinaryFormatter 反序列化时,该工具可以触发 .NET 程序集加载执行

    当前的小工具在使用来自 jscript/vbscript/vba 的 BinaryFormatter 反序列化时会触发对 Activator.CreateInstance() 的调用,这意味着它可用于通过默认/公共构造函数触发您选择的 .NET 程序集的执行。 该工具的创建...

    Dahomey.Cbor:.Net(C#)的高性能CBOR(RFC 7049)序列化框架

    面向.Net(C#)的高性能序列化框架 支持的.NET版本 .NET标准2.0 .NET Core 3.1 .NET 5.0 特征 从/到流的序列化/反序列化,字节缓冲区 对象模型 映射到任何.Net类 基于区分符约定的可扩展多态性支持 可扩展的命名...

    ADO.NET本质论.pdf

    7.3 序列化、封送和dataset 7.4 类型化的dataset 7.5 xmldatadocument类 7.5.1 xmldatadocument和dataset 7.5.2 xmldatadocument和datadocumentxpathnavigator 7.6 数据库和xml的重要意义 7.6.1 xml...

    用.NET精简版2.0和SQL Server 2005打造强力智能客户端

    库类支持序列化/反序列化 XmlSerializer 引擎 Serialize 方法将类转化为 XML Deserialize 重建类实例 序列化控制 类必须具有缺省构造函数 Attributes 控制细节 XmlElement XmlAttribute 以上都是我从课件...

    PHP函数库,PHP函数大全,PHP函数实例,PHP函数手册,PHP5函数库实例

    检测是否序列化后的字符串 模仿JAVASCRIPT的ESCAPE和UNESCAPE函数的功能 用curl函数读取远程文件 用file_getcontents提交数据 用php生成扭曲,有角度的验证图片(支持中文) 用正则加亮关键字 程序运行过程中...

    主页:.NET的可配置和可扩展Xml序列化器

    在这里,您将找到一个.NET序列化器: 专门从事基于的对象图序列化具有强大的扩展模型以久经考验的可靠XML格式运行。 :sparkling_heart:“但为什么?” 经典的System.Xml.XmlSerializer提出了一些挑战: 不支持使用...

    serialize-like-php:使用javascript模拟php的序列化和反序列化功能

    模拟用于序列化和反序列化的php函数。 对于使用(或迁移!)php应用程序很有帮助。 学分 我只是将其打包并添加了测试。 这些是写这些内容的人: 连载: discuss at: http://phpjs.org/functions/serialize/ ...

    .net技术资料大全(语言规范 源码教程 学习笔记 技术资料 .net代码生成器)

    asp.net常用函数表.txt Asp.net的身份验证.txt ASP导出Excel数据的四种方法.txt C#调用存储过程.txt CheckBox控件.txt datagrid排序_选择_分页.txt DataSet对象.txt DotNET WinForm FAQ 16个.txt excel打印...

    国内最全的.net面试题目

    序列化:序列化是将对象转换为容易传输的格式的过程。例如,可以序列化一个对象,然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象。在另一端,反序列化将从该流重新构造对象。 5.概述o/r mapping 的原理...

    asp.net技术内幕(1)

    第一部分 使用ASP.NET Web表单 &lt;br&gt;第1章 建立ASP.NET页面 &lt;br&gt;1.1 ASP.NET和.NET框架 1.1.1 .NET框架类库 1.1.2 理解名称空间 1.1.3 标准的ASP.NET名称空间 1.1.4 与.NET框架兼容的语言 ...

    .net 常用类集锦

    常用类集锦,内有各常用类与函数,可省去大部分时间编写烦锁的代码.

    Visual.Basic.2010.&.NET4.高级编程(第6版)-文字版.pdf

    9.2 xml序列化 343 9.3 system.xml文档支持 348 9.4 xml流样式分析程序 348 9.4.1 写入xml流 349 9.4.2 读取xml流 352 9.4.3 文档对象模型(dom) 360 9.5 xslt转换 364 9.5.1 使用xslt转换不同的xml...

    asp.net面试题

    序列化:序列化是将对象转换为容易传输的格式的过程。例如,可以序列化一个对象,然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象。在另一端,反序列化将从该流重新构造对象。 5.概述o/r mapping 的...

    febird C++ 库(附带所有源码)

    该库也实现了一个不需要IDL的rpc,使用几个宏,很方便的自动完成函数参数的序列化,比MFC的MessageMap?还要方便。 使用时请checkout最新版,下载的那个版本比较旧了 @see ...

    用C#写的WinForm桌面小程序---考试倒计时,用到了序列化反序列化和窗体之委托传值源码

    要准备软考的学习了,用C#写的WinForm桌面小程序,计算倒计时提醒自己.也可用于阻击疫情居家隔离倒计时 1.小程序用到了窗体间传值的两种方法:构造函数传值 ,委托传值 ,值得初学...2.用到了序列化和反序列化持久化数据

    ASP.net技术内幕

    本书是关于使用ASP.NET建立网站的完整参考书,书中包含数百个代码示例,读者可以使用这些示例开始建立自己的网站 前言 &lt;br/&gt;第一部分 使用ASP.NET Web表单 &lt;br/&gt;第1章 建立ASP.NET页面 &lt;br/&gt;1.1 ...

Global site tag (gtag.js) - Google Analytics