<bdo id='bjumh'></bdo><ul id='bjumh'></ul>

  • <legend id='bjumh'><style id='bjumh'><dir id='bjumh'><q id='bjumh'></q></dir></style></legend>

  • <i id='bjumh'><tr id='bjumh'><dt id='bjumh'><q id='bjumh'><span id='bjumh'><b id='bjumh'><form id='bjumh'><ins id='bjumh'></ins><ul id='bjumh'></ul><sub id='bjumh'></sub></form><legend id='bjumh'></legend><bdo id='bjumh'><pre id='bjumh'><center id='bjumh'></center></pre></bdo></b><th id='bjumh'></th></span></q></dt></tr></i><div id='bjumh'><tfoot id='bjumh'></tfoot><dl id='bjumh'><fieldset id='bjumh'></fieldset></dl></div>

    1. <tfoot id='bjumh'></tfoot>

      <small id='bjumh'></small><noframes id='bjumh'>

        使用 Serializable 属性 &amp; 有什么区别?实现 ISerializable?

        时间:2023-07-27
          <tbody id='IaxpJ'></tbody>
        <i id='IaxpJ'><tr id='IaxpJ'><dt id='IaxpJ'><q id='IaxpJ'><span id='IaxpJ'><b id='IaxpJ'><form id='IaxpJ'><ins id='IaxpJ'></ins><ul id='IaxpJ'></ul><sub id='IaxpJ'></sub></form><legend id='IaxpJ'></legend><bdo id='IaxpJ'><pre id='IaxpJ'><center id='IaxpJ'></center></pre></bdo></b><th id='IaxpJ'></th></span></q></dt></tr></i><div id='IaxpJ'><tfoot id='IaxpJ'></tfoot><dl id='IaxpJ'><fieldset id='IaxpJ'></fieldset></dl></div>

        <tfoot id='IaxpJ'></tfoot>
        <legend id='IaxpJ'><style id='IaxpJ'><dir id='IaxpJ'><q id='IaxpJ'></q></dir></style></legend>

        <small id='IaxpJ'></small><noframes id='IaxpJ'>

              • <bdo id='IaxpJ'></bdo><ul id='IaxpJ'></ul>

                  本文介绍了使用 Serializable 属性 &amp; 有什么区别?实现 ISerializable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用Serializable属性和实现ISerializable接口有什么区别?

                  What's the difference between using the Serializable attribute and implementing the ISerializable interface?

                  推荐答案

                  当你使用 SerializableAttribute 属性 您在编译时将属性放在字段上,这样在运行时,序列化工具通过对类/模块/程序集类型执行反射,将知道根据属性序列化什么.

                  When you use the SerializableAttribute attribute you are putting an attribute on a field at compile-time in such a way that when at run-time, the serializing facilities will know what to serialize based on the attributes by performing reflection on the class/module/assembly type.

                  [Serializable]
                  public class MyFoo { … }
                  

                  上面表明序列化工具应该序列化整个类MyFoo,而:

                  The above indicates that the serializing facility should serialize the entire class MyFoo, whereas:

                  public class MyFoo
                  {
                      private int bar;
                  
                      [Serializable]
                      public int WhatBar
                      {
                         get { return this.bar; }
                      }
                  }
                  

                  使用该属性可以选择性地选择需要序列化的字段.

                  Using the attribute you can selectively choose which fields needs to be serialized.

                  当您实现 ISerializable 接口,通过覆盖 GetObjectData SetObjectData(并且通过提供 MyFoo(SerializationInfo info, StreamingContext context) 形式的构造函数),可以更好地控制数据的序列化.

                  When you implement the ISerializable interface, the serialization effectively gets overridden with a custom version, by overriding GetObjectData and SetObjectData (and by providing a constructor of the form MyFoo(SerializationInfo info, StreamingContext context)), there would be a finer degree of control over the serializing of the data.

                  另请参阅 此 StackOverflow 上的自定义序列化示例.它展示了如何使序列化与序列化数据的不同版本保持向后兼容.

                  See also this example of a custom serialization here on StackOverflow. It shows how to keep the serialization backwards-compatible with different versionings of the serialized data.

                  希望这会有所帮助.

                  这篇关于使用 Serializable 属性 &amp; 有什么区别?实现 ISerializable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:继承如何对属性起作用? 下一篇:C# 中的属性

                  相关文章

                  <i id='TCT12'><tr id='TCT12'><dt id='TCT12'><q id='TCT12'><span id='TCT12'><b id='TCT12'><form id='TCT12'><ins id='TCT12'></ins><ul id='TCT12'></ul><sub id='TCT12'></sub></form><legend id='TCT12'></legend><bdo id='TCT12'><pre id='TCT12'><center id='TCT12'></center></pre></bdo></b><th id='TCT12'></th></span></q></dt></tr></i><div id='TCT12'><tfoot id='TCT12'></tfoot><dl id='TCT12'><fieldset id='TCT12'></fieldset></dl></div>

                  1. <legend id='TCT12'><style id='TCT12'><dir id='TCT12'><q id='TCT12'></q></dir></style></legend>
                    <tfoot id='TCT12'></tfoot>

                    <small id='TCT12'></small><noframes id='TCT12'>

                      <bdo id='TCT12'></bdo><ul id='TCT12'></ul>