Question 3) Application Development Foundation

Posted on
Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone

Objective: Implementing Serialization and Input/Output Functionality in a .NET Framework Application
SubObjective: Control the serialization of an object into XML format by using the System.Xml.Serialization namespace

Single Answer Multiple Choice

You are an application developer for a company. You create the following class:

<Serializable()>_
Public Class Vehicle
Public VIN As String
Public Make As String
Private Model As String
Private Year As Integer
Private Owner As String
End Class

For security reasons, you do not want the Owner field to be persisted when a Vehicle object is serialized. What should you do?

A. Do nothing. Private fields are never persisted when using binary serialization.
B. Apply the OptionalField attribute to the Owner field.
C. Apply the NonSerialized attribute to the Owner field.
D. Have the Vehicle class implement the IFormatter interface for custom serialization.

Answer:
C. Apply the NonSerialized attribute to the Owner field.

Tutorial:
You should apply the NonSerialized attribute to the Owner field as follows:

<NonSerialized()> _
Private Owner As String

This will ensure that the Owner field will not be serialized, but it will allow all other fields to be serialized normally.

You should not “do nothing” because all fields marked private or otherwise are persisted when using binary serialization. XML serialization is the only type that does not persist private fields.

You should not apply the OptionalField attribute because this is used for deserialization. The Owner field would still persist when the object was serialized. The OptionalField attribute would allow an older version of the Vehicle class that did not have an Owner field to ignore the value when deserializing.

You should not have the Vehicle class inherit the IFormatter interface for custom serialization because this would require excessive developer effort. When implementing the IFormatter interface, the code in the Serialize method could ignore the Owner field, but at the cost of manually persisting the other fields.

Reference:
MSDN2 Library > Development Tools and Languages > Visual Studio > .NET Framework Programming in Visual Studio > .NET Framework Advanced Development > Serialization > Binary Serialization

MSDN2 Library > Development Tools and Languages > Visual Studio > .NET Framework Programming in Visual Studio > .NET Framework Advanced Development > Serialization > Binary Serialization > Selective Serialization

 

These questions are derived from the Self Test Software Practice Test for Microsoft exam #70-536VB: TS: Microsoft .NET Framework 2.0 – Application Development Foundation (VB.NET)
Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone
cmadmin

ABOUT THE AUTHOR

Posted in Archive|

Comment:

Leave a comment

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

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