How to disable Serialization of a Class property

Some time we require to disable serialization of a class property, And the <NonSerialized()> attribute will not allowed in Property declarations. After Googleing I found one solution.

<Serializable()> Public Class MySerClass
    <NonSerialized()> _
    Private m_Filename As String
    <System.Xml.Serialization.XmlIgnore()> _
    Public Property FileName() As String
        Get
            Return m_Filename
        End Get
        Set(ByVal value As String)
            m_Filename = value
        End Set
    End Property
End Class

By doing this, the Filename property will not be serialized.

No related content found.

This entry was posted in .Net. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>