0% found this document useful (0 votes)
7 views

complete-reference-vb_net_77

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

complete-reference-vb_net_77

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Observations

Tip Notice how we can simply call File.OpenRead and feed it to the
stream.
Next, we have to create a new SoapFormatter just as we did earlier. The code that achieved this is as
follows:

Dim meData As New SoapFormatter()

Finally, we call the Deserialize method and close the file when we are done. Notice that we use CType to
explicitly convert the holder type to the type represented in deserialized data.

aClone = CType(meData.Deserialize(fileForRecover), _
BaseNodeCollection)
fileForRecover.Close()

At this point, our job is not yet done. We got the data back, but it is in an object that is not currently being
referenced by our application. However, all that's left to do is to copy the data in one object to the other. There
are several different ways to recover the data, but just assigning the new object to the old object's reference
variable (List) is the easiest (as long as the old object is not yet holding active data that will be lost when you
cut its lifeline).

To call the deserializer method at run time is not difficult to achieve. You could call it shortly after startup, as
demonstrated in the following code, to enhance the console application:

Public Sub New


MyBase.New
List.PlayListIn()
End Sub

That's all there is to the serialization. Incidentally, for local applications that do not need to serialize across
network streams, it would be faster and more secure to use the binary formatter class.

Observations

While this chapter might be big enough to be called a book, it still represents a tiny portion of the I/O and data
processing ability of .NET. This chapter demonstrated the design and creation of several business objects that
are useful in a variety of data processing scenarios. We used a variety of facilities in the .NET Framework to
achieve the results. These included the exhaustive String, character and text manipulation classes, the file I/O
and directory management classes, classes that empower us to read and write to streams of text and binary
data, and finally, that critical requirement all businesses now harp after, XML support.

In the next chapter, we'll complete the mission by providing smart user interface elements to all of this
functionality.

561

You might also like