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

    1. <small id='ne0x8'></small><noframes id='ne0x8'>

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

        NonSerialized 和 Xml.Serialization.XmlIgnore 之间的区别?

        Difference between NonSerialized and Xml.Serialization.XmlIgnore?(NonSerialized 和 Xml.Serialization.XmlIgnore 之间的区别?)
        1. <small id='VzzsM'></small><noframes id='VzzsM'>

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

              <tbody id='VzzsM'></tbody>
              • <bdo id='VzzsM'></bdo><ul id='VzzsM'></ul>

                  <legend id='VzzsM'><style id='VzzsM'><dir id='VzzsM'><q id='VzzsM'></q></dir></style></legend>
                  <tfoot id='VzzsM'></tfoot>
                  本文介绍了NonSerialized 和 Xml.Serialization.XmlIgnore 之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们正在从 XML 中序列化/反序列化一个类,但是我们想要排除该类中的一些属性和字段.

                  System.NonSerializedSystem.Xml.Serialization.XmlIgnore 属性似乎可以完成这项工作,但它们之间有什么区别?看来我们可以在类的属性或字段上使用 XmlIgnore.但是 NonSerialized 只能用于字段.是否有任何理由不在每种情况下都使用 XmlIgnore,如果是,NonSerialized 属性的用途是什么以及为什么使用方式不同?

                  <小时>

                  这是允许的:

                  <System.NonSerialized()>_公共 Foo 作为字符串

                  <小时>

                  这是允许的:

                  <System.Xml.Serialization.XmlIgnore()>_公共 Foo 作为字符串

                  <小时>

                  这是允许的:

                  <System.Xml.Serialization.XmlIgnore()>_公共属性 Bar() 作为字符串得到返回_Bar结束获取设置(ByVal 值作为字符串)_Bar = 值结束集结束属性

                  <小时>

                  但这是不允许的:

                  <System.NonSerialized()>_公共属性 Bar() 作为字符串得到返回_Bar结束获取设置(ByVal 值作为字符串)_Bar = 值结束集结束属性

                  解决方案

                  NonSerialized 适用于比 XML 更多类型的序列化.如果要序列化为二进制或 SOAP,则使用 NonSerialized;如果使用 XmlSerializer 严格序列化为 XML,则使用 XmlIgnore.请参阅 MSDN 上 NonSerializedAttribute 类的备注部分.p>

                  We're serializing/deserializing a class from XML but there are properties and fields in the class which we want to exclude.

                  The System.NonSerialized and System.Xml.Serialization.XmlIgnore attributes seem to do the job but what's the difference between them? It seems we can use XmlIgnore on either properties or fields of the class. But NonSerialized can only be used on fields. Is there any reason not to use XmlIgnore in every case, and if so what's the purpose of the NonSerialized attribute and why the difference in usage?


                  This is allowed:

                  <System.NonSerialized()> _
                  Public Foo As String
                  


                  This is allowed:

                  <System.Xml.Serialization.XmlIgnore()> _
                  Public Foo As String
                  


                  This is allowed:

                  <System.Xml.Serialization.XmlIgnore()> _
                  Public Property Bar() As String
                      Get
                          Return _Bar
                      End Get
                      Set(ByVal value As String)
                          _Bar = value
                      End Set
                  End Property
                  


                  But this is not allowed:

                  <System.NonSerialized()> _
                  Public Property Bar() As String
                      Get
                          Return _Bar
                      End Get
                      Set(ByVal value As String)
                          _Bar = value
                      End Set
                  End Property
                  

                  解决方案

                  NonSerialized applies to more types of serialization than XML. You would use NonSerialized if you were serializing to binary or SOAP, and XmlIgnore if you were strictly serializing to XML using an XmlSerializer. See the remarks section of the NonSerializedAttribute class at MSDN.

                  这篇关于NonSerialized 和 Xml.Serialization.XmlIgnore 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)
                    <bdo id='IX4SB'></bdo><ul id='IX4SB'></ul>

                      <legend id='IX4SB'><style id='IX4SB'><dir id='IX4SB'><q id='IX4SB'></q></dir></style></legend>

                    1. <small id='IX4SB'></small><noframes id='IX4SB'>

                          <tfoot id='IX4SB'></tfoot>
                            <tbody id='IX4SB'></tbody>

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