Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
programming4us
Windows 7

Microsoft Visio 2010 : Custom Serialization

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
6/13/2011 5:36:00 PM
In most cases the .NET built-in serialization engine is good enough. But if it does not meet your particular needs, you can override the serialization process with custom serialization. Basically this means implementing the ISerializable interface that requires the implementation of the GetObjectData method. Such a method is important because it is invoked during serialization. Moreover a custom implementation of the class constructor must be provided. Basically you have to first reproduce at least what built-in formatters do during serialization. Code in Listing 1 shows how to provide custom serialization for the Person class.
Listing 1. Providing Custom Serialization
Imports System.Runtime.Serialization
Imports System.Security.Permissions

<Serializable()>
Public Class Person
Implements ISerializable

Public Overridable Property FirstName As String
Public Overridable Property LastName As String
Public Overridable Property Age As Integer

<SecurityPermission(SecurityAction.Demand,
SerializationFormatter:=True)>
Protected Sub GetObjectData(ByVal info As System.Runtime.Serialization.
SerializationInfo,
ByVal context As System.Runtime.Serialization.
StreamingContext) _
Implements System.Runtime.Serialization.ISerializable.
GetObjectData

info.AddValue("First name", Me.FirstName)
info.AddValue("Last name", Me.LastName)
info.AddValue("Age", Me.Age)
End Sub

'At deserialization time
Protected Sub New(ByVal info As SerializationInfo,
ByVal context As StreamingContext)
MyBase.New()
Me.FirstName = info.GetString("First name")
Me.LastName = info.GetString("Last name")
Me.Age = info.GetInt32("Age")
End Sub
End Class


The GetObjectData method is basically invoked when you pass an object to the Serialize method of a formatter and require an info argument of type SerializationInfo. This class stores all information needed for serialization. It exposes an AddValue method that stores data and a value utilized for recognizing data. Notice that the information is retrieved by the special constructor implementation that is invoked at deserialization time via GetXXX methods where XXX corresponds to .NET types such as Int32, Boolean, Short, and so on. Also notice how GetObjectData is decorated with the SecurityPermission attribute demanding for permissions about the serialization formatter. This is necessary because the permission is allowed only to full-trusted code, thus intranet and Internet zones are not allowed. Both GetObjectData and the constructor are Protected so that derived classes can still take advantage of them but are prevented from being public. If you are sure that your class will not be inherited, GetObjectData can also be Private.

Inheritance Tip

When you create a class that inherits from another class where ISerializable is implemented, if you add new members, you can also provide a new implementation of both GetObjectData and the constructor.


Implementing ISerializable is not the only way for controlling serialization. You can control serialization events, too.

Serialization Events

The serialization process raises four events, which are summarized in Table 1.

Table 1. Serialization Events
EventDescription
OnSerializingOccurs just before serialization begins
OnSerializedOccurs just after serialization completes
OnDeserializingOccurs just before deserialization begins
OnDeserializedOccurs just after deserialization completes

Serialization events are handled differently than classic events. There is an attribute for each event that you can handle as follows:

'Invoke this method before
'serialization begins
<OnSerializing()>
Private Sub FirstMethod()

End Sub

'Invoke this method after
'serialization completes
<OnSerialized()>
Private Sub SecondMethod()

End Sub

'Invoke this method before
'deserialization begins
<OnDeserializing()>
Private Sub ThirdMethod()

End Sub

'Invoke this method after
'deserialization completes
<OnDeserialized()>
Private Sub FourthMethod()

End Sub

The runtime takes care of invoking the specified method according to the moment represented by each attribute. In this way you can provide additional actions based on serialization events.

Other -----------------
- Microsoft Visio 2010 : Connecting Shapes with Dynamic Connectors
- Microsoft Visio 2010 : Copying and Pasting Shapes & Connecting Shapes with Lines
- Microsoft PowerPoint 2010 : Working Together on Office Documents - Creating Office Documents on Windows Live
- Microsoft PowerPoint 2010 : Working Together on Office Documents - Setting Folder Permissions on Windows Live
- Visual Basic 2010 : XML Serialization
- Visual Basic 2010 : Objects Serialization (part 2) - Soap Serialization & Providing Serialization for Custom Objects
- Visual Basic 2010 : Objects Serialization (part 1) - Binary Serialization
- Microsoft Excel 2010 : Editing a Chart & Moving and Resizing a Chart
- Microsoft Excel 2010 - Choosing the Right Type of Chart & Creating a Chart
- Microsoft PowerPoint 2010 : Working Together on Office Documents - Working with Folders on Windows Live
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server