Click here to Skip to main content
Click here to Skip to main content

Visual Studio 2010 – Visual Basic New Feature – NonSerialized Events

By , 17 Nov 2009
 

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.

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Karl Shifflett
Architect Gayle Manufacturing Company
United States United States
Member
Karl loves .NET, WPF, WCF, ASP.NET, VB.NET and C#.
 
Awards:
 
  • December 2008 VB.NET Code Project Article Award
  • 2009 Code Project MVP
  • 2008 Code Project MVP
  • 2008 Microsoft MVP - Client App Dev
  • December 2007 VB.NET Code Project Article Award
  • Gold Medal Winner at IBM's 1998 PROIV Programming Contest in Las Vegas
Click here to check out my Blog
 
Click here to learn about Mole 2010 debugging tool for Visual Studio 2010
 
Click here to read about XAML Power Toys
 

Just a grain of sand on the worlds beaches.


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 17 Nov 2009
Article Copyright 2009 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid