好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

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

@font-face { font-family: 宋体 } @font-face { font-family: "Cambria Math" } @font-face { font-family: Calibri } @font-face { font-family: "@宋体" } @font-face { font-family: Consolas } p.MsoNormal, li.MsoNormal, div.MsoNormal { mso-style-unhide: no; mso-style-qformat: yes; mso-style-parent: ""; margin: 0 0 0.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: 10pt; 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 { mso-page-border-surround-header: no mso-page-border-surround-footer: no } @page Section1 { size: 612.0pt 792.0pt margin-top: 72pt margin-right: 90pt margin-bottom: 72pt margin-left: 90pt mso-header-margin: 36.0pt mso-footer-margin: 36.0pt mso-paper-source: 0 } div.Section1 { page: Section1 }

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

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

@font-face { font-family: 宋体 } @font-face { font-family: "Cambria Math" } @font-face { font-family: Calibri } @font-face { font-family: "@宋体" } @font-face { font-family: Consolas } p.MsoNormal, li.MsoNormal, div.MsoNormal { mso-style-unhide: no; mso-style-qformat: yes; mso-style-parent: ""; margin: 0 0 0.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: 10pt; 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 { mso-page-border-surround-header: no mso-page-border-surround-footer: no } @page Section1 { size: 612.0pt 792.0pt margin-top: 72pt margin-right: 90pt margin-bottom: 72pt margin-left: 90pt mso-header-margin: 36.0pt mso-footer-margin: 36.0pt mso-paper-source: 0 } div.Section1 { page: Section1 }

另外知道了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平台序列化函数相关的问题的详细内容...

  阅读:45次