Vb Net Serialize A Structure

-->

You could serialize into other stream objects such as file streams if you want. The code calls the serializer's Serialize method, passing it the stream to serialize into (the StringWriter) and the Person object to serialize. The program displays the serialization in a text box and then closes the StringWriter. Sep 24, 2007  Serialization is the term for the act of saving (or serializing) an object onto a storage Medium — a file, a database field, a buffer in memory — and later deserializing it from the storage medium to re-create an object instance that can be considered identical to the original one. Mar 09, 2008  So, what is the solution? We can serialize the structure and write the serialized object to a binary file. Using the code. First of all, open Visual Studio 2008 and create a new Visual Basic 2008 Console Application. We could have a very simple Structure called Software, which contains information about a computer program.

Definition

Indicates that a class can be serialized. This class cannot be inherited.

Inheritance
AttributeAttributeAttributeAttribute
SerializableAttributeSerializableAttributeSerializableAttributeSerializableAttribute
Attributes

Examples

The following example demonstrates serialization of an object that is marked with the SerializableAttribute attribute. To use the BinaryFormatter instead of the SoapFormatter, uncomment the appropriate lines.

Remarks

Serialize

Apply the SerializableAttribute attribute to a type to indicate that instances of this type can be serialized. The common language runtime throws SerializationException if any type in the graph of objects being serialized does not have the SerializableAttribute attribute applied.

Apply the SerializableAttribute attribute even if the class also implements the ISerializable interface to control the serialization process.

When you apply the SerializableAttribute attribute to a type, all private and public fields are serialized by default. You can control serialization more granularly by implementing the ISerializable interface to override the serialization process.

Vb Net Serialize A Structure

Or you can exclude fields from serialization by applying the NonSerializedAttribute attribute to the field. If a field of a serializable type contains a pointer, a handle, or some other data structure that is specific to a particular environment, and cannot be meaningfully reconstituted in a different environment, then you might want to apply the NonSerializedAttribute attribute to that field.

For more information about using attributes, see Attributes. For more information about serialization, see System.Runtime.Serialization.

Constructors

SerializableAttribute()SerializableAttribute()SerializableAttribute()SerializableAttribute()

Initializes a new instance of the SerializableAttribute class.

Methods

Equals(Object)Equals(Object)Equals(Object)Equals(Object)

Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode()GetHashCode()GetHashCode()GetHashCode()

Returns the hash code for this instance.

(Inherited from Attribute)
GetType()GetType()GetType()GetType()

Gets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute()IsDefaultAttribute()IsDefaultAttribute()IsDefaultAttribute()

When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object)Match(Object)Match(Object)Match(Object)

When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone()MemberwiseClone()MemberwiseClone()MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()ToString()ToString()ToString()

Returns a string that represents the current object.

(Inherited from Object)
Structure

Explicit Interface Implementations

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32)_Attribute.GetTypeInfoCount(UInt32)_Attribute.GetTypeInfoCount(UInt32)_Attribute.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Properties

TypeIdTypeIdTypeIdTypeId

When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

Applies to

Vb Serialize Object

See also

Xmlserializer Vb

  • AttributeAttributeAttributeAttribute