Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Visual Studio 2010 – Visual Basic New Feature – NonSerialized Events

0.00/5 (No votes)
17 Nov 2009 1  
A long time feature request has been added to Visual Basic 10 that ships with Visual Studio 2010; decorating an Event as NonSerialized.

A long time feature request has been added to Visual Basic 10 that ships with Visual Studio 2010; decorating an Event as NonSerialized.

In prior versions of Visual Basic, developers had to implement a Custom Event or another workaround when their types needed to expose an Event and they had to be Serializable. C# had this capability, now Visual Basic does too!

A very common scenario is a class that implements INotifyPropertyChanged and must also be Serializable.

Visual Basic developers can now decorate the Event with the NonSerialized attribute. The compiler does the rest for you.

VB.NET
Imports System.ComponentModel

<Serializable()>
Public Class Customer
    Implements INotifyPropertyChanged

#Region " INotifyPropertyChanged Serializable "
     'New VB 10 feature!
    <NonSerialized()>
    Public Event PropertyChanged(
                  ByVal sender As Object,
                  ByVal e As System.ComponentModel.PropertyChangedEventArgs) _
                  Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

    Protected Sub OnPropertyChanged(ByVal strPropertyName As String)
        If Me.PropertyChangedEvent IsNot Nothing Then
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(strPropertyName))
        End If
    End Sub

#End Region

End Class

Have a great day.

Just a grain of sand on the world's beaches.

Posted in CodeProject, Tips, VB.NET, Visual Studio 2010, WPF General

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here