Preventing serialization of properties in VB.NET

风流意气都作罢 提交于 2019-12-07 04:53:10

问题


I have a VB.NET class which I'm serializing via XML in an asmx file. I've added attributes to the datamember I want to ignore in serialization, but it's still returned. I also have the <DataContract()> attribute on my class and the DataMember attribute on all properties which should be serialized. My property declaration is:

    <ScriptIgnore()> _
    <IgnoreDataMember()> _
    Public Property Address() As SomeObject

回答1:


By adding an attribute to the backing field and converting it from an auto-property, I eventually got the proprty to stop serializing:

<NonSerialized()> _
Private _address As SomeObject = Nothing
<ScriptIgnore()> _
<IgnoreDataMember()> _
<Xmlignore()>
Public Property address() As SomeObject
    Get
        Return _address
    End Get
    Set(ByVal value As SomeObject)
        _address = value
    End Set
End Property



回答2:


Have you tried the NonSerialized attribute:

<NonSerialized()> _
Public Property Address() As SomeObject

http://msdn.microsoft.com/en-us/library/system.nonserializedattribute.aspx



来源:https://stackoverflow.com/questions/6746444/preventing-serialization-of-properties-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!