System.Runtime.Serialization.Formatter Class

Assembly: Mscorlib.dll
Namespace: System.Runtime.Serialization
Summary
Provides base functionality for the common language runtime serialization formatters.
This class is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
[Serializable]
public abstract class Formatter : IFormatter
Remarks
Formatter is the abstract base class for all runtime serialization formatters, and provides some helper methods for implementing the IFormatter interface. The Formatter also manages queuing objects for serialization and generating IDs on a per-object basis.

Notes to inheritors: When you inherit from Formatter, you must override the following members: Formatter.Serialize, Formatter.Deserialize, Formatter.WriteArray, Formatter.WriteBoolean, Formatter.WriteByte, Formatter.WriteChar, Formatter.WriteDateTime, Formatter.WriteDecimal, Formatter.WriteDouble, Formatter.WriteInt16, Formatter.WriteInt32, Formatter.WriteInt64, Formatter.WriteObjectRef, Formatter.WriteSByte, Formatter.WriteSingle, Formatter.WriteTimeSpan, Formatter.WriteUInt16, Formatter.WriteUInt32, Formatter.WriteUInt64, Formatter.WriteValueType, Formatter.SurrogateSelector, Formatter.Binder, and Formatter.Context.
See also:
System.Runtime.Serialization Namespace | ObjectIDGenerator | MSDN: serialization

System.Runtime.Serialization.Formatter Member List:

Public Properties
Binder Read-write

When overridden in a derived class, gets or sets the SerializationBinder used with the current formatter.
Context Read-write

When overridden in a derived class, gets or sets the StreamingContext used for the current serialization.
SurrogateSelector Read-write

When overridden in a derived class, gets or sets the ISurrogateSelector used with the current formatter.
Public Methods
Deserialize When overridden in a derived class, deserializes the stream attached to the formatter when it was created, creating a graph of objects identical to the graph originally serialized into that stream.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
Serialize When overridden in a derived class, serializes the graph of objects with the specified root to the stream already attached to the formatter.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the Formatter class.
Protected Fields
m_idGenerator Contains the ObjectIDGenerator used with the current formatter.
m_objectQueue Contains a Queue of the objects left to serialize.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
GetNext Returns the next object to serialize, from the formatter's internal work queue.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.
Schedule Schedules an object for later serialization.
WriteArray When overridden in a derived class, writes an array to the stream already attached to the formatter.
WriteBoolean When overridden in a derived class, writes a Boolean value to the stream already attached to the formatter.
WriteByte When overridden in a derived class, writes an 8-bit unsigned integer to the stream already attached to the formatter.
WriteChar When overridden in a derived class, writes a Unicode character to the stream already attached to the formatter.
WriteDateTime When overridden in a derived class, writes a DateTime value to the stream already attached to the formatter.
WriteDecimal When overridden in a derived class, writes a Decimal value to the stream already attached to the formatter.
WriteDouble When overridden in a derived class, writes a double-precision floating-point number to the stream already attached to the formatter.
WriteInt16 When overridden in a derived class, writes a 16-bit signed integer to the stream already attached to the formatter.
WriteInt32 When overridden in a derived class, writes a 32-bit signed integer to the stream.
WriteInt64 When overridden in a derived class, writes a 64-bit signed integer to the stream.
WriteMember Inspects the type of data received, and calls the appropriate Write method to perform the write to the stream already attached to the formatter.
WriteObjectRef When overridden in a derived class, writes an object reference to the stream already attached to the formatter.
WriteSByte When overridden in a derived class, writes an 8-bit signed integer to the stream already attached to the formatter.
WriteSingle When overridden in a derived class, writes a single-precision floating-point number to the stream already attached to the formatter.
WriteTimeSpan When overridden in a derived class, writes a TimeSpan value to the stream already attached to the formatter.
WriteUInt16 When overridden in a derived class, writes a 16-bit unsigned integer to the stream already attached to the formatter.
WriteUInt32 When overridden in a derived class, writes a 32-bit unsigned integer to the stream already attached to the formatter.
WriteUInt64 When overridden in a derived class, writes a 64-bit unsigned integer to the stream already attached to the formatter.
WriteValueType When overridden in a derived class, writes a value of the given type to the stream already attached to the formatter.

Hierarchy:


System.Runtime.Serialization.Formatter Member Details

ctor #1
Summary
Initializes a new instance of the Formatter class.
This class is not CLS Compliant


Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
protected Formatter();
Remarks
Creates a Queue for objects to serialize and an ObjectIDGenerator to generate IDs for them.
See also:
ObjectIDGenerator

Return to top


Field: m_idGenerator
Summary
Contains the ObjectIDGenerator used with the current formatter.
This class is not CLS Compliant

C# Syntax:
protected ObjectIDGenerator m_idGenerator;
Remarks
The ObjectIDGenerator maintains a list of the objects that have been identified and the IDs that they were given.

Return to top


Field: m_objectQueue
Summary
Contains a Queue of the objects left to serialize.
This class is not CLS Compliant

C# Syntax:
protected Queue m_objectQueue;
Remarks
Objects scheduled for serialization with the Formatter.Schedule method are pushed on the queue.
See also:
Queue

Return to top


Property: Binder (read-write)
Summary
When overridden in a derived class, gets or sets the SerializationBinder used with the current formatter.
This class is not CLS Compliant

C# Syntax:
public abstract SerializationBinder Binder {get; set;}
Implements:
IFormatter.Binder
Remarks
The SerializationBinder performs lookups for types from the type names passed during deserialization. If no SerializationBinder is set, a default is used.

Notes to inheritors: You must implement this property in a derived class.

Return to top


Property: Context (read-write)
Summary
When overridden in a derived class, gets or sets the StreamingContext used for the current serialization.
This class is not CLS Compliant

C# Syntax:
public abstract StreamingContext Context {get; set;}
Implements:
IFormatter.Context
Remarks
The StreamingContext is an indication of either the source of the bits being deserialized or the destination of the bits being serialized. It has no impact on default serialization, but is passed as an argument to ISerializable and ISerializationSurrogate.

Notes to inheritors: You must implement this property in a derived class.

Return to top


Property: SurrogateSelector (read-write)
Summary
When overridden in a derived class, gets or sets the ISurrogateSelector used with the current formatter.
This class is not CLS Compliant

C# Syntax:
public abstract ISurrogateSelector SurrogateSelector {get; set;}
Implements:
IFormatter.SurrogateSelector
Remarks
Use the SurrogateSelector to look up implementations of ISerializationSurrogate that control the serialization of a particular type.

Note If an object type has a matching surrogate, then serialization and deserialization are handed off to the surrogate even if the type implements the ISerializable interface.

Notes to inheritors: You must implement this property in a derived class.

Return to top


Method: Deserialize(
   Stream serializationStream
)
Summary
When overridden in a derived class, deserializes the stream attached to the formatter when it was created, creating a graph of objects identical to the graph originally serialized into that stream.
This class is not CLS Compliant

C# Syntax:
public abstract object Deserialize(
   Stream serializationStream
);
Parameters:

serializationStream

The stream to deserialize.

Return Value:
The top object of the deserialized graph of objects.
Implements:
IFormatter.Deserialize
Remarks


Notes to inheritors: You must implement this method in a derived class.
See also:
MSDN: serialization

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
This class is not CLS Compliant

C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
This class is not CLS Compliant

C# Syntax:
~Formatter();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
This class is not CLS Compliant

C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetNext(
   out long objID
)
Summary
Returns the next object to serialize, from the formatter's internal work queue.
This class is not CLS Compliant

C# Syntax:
protected virtual object GetNext(
   out long objID
);
Parameters:

objID

The ID assigned to the current object during serialization.

Return Value:
The next object to serialize.
Exceptions
Exception Type Condition
SerializationException The next object retrieved from the work queue did not have an assigned ID.
Remarks
Objects are returned in a first in first out order based on how they were passed to Formatter.Schedule. The ID of the object is put into the objID parameter and the object is returned from the function.
See also:
ObjectIDGenerator

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
This class is not CLS Compliant

C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
This class is not CLS Compliant

C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Schedule(
   object obj
)
Summary
Schedules an object for later serialization.
This class is not CLS Compliant

C# Syntax:
protected virtual long Schedule(
   object obj
);
Parameters:

obj

The object to schedule for serialization.

Return Value:
The object ID assigned to the object.
Remarks
Formatter.Schedule obtains an ID for the object and puts it on the queue for later serialization if this is a new object ID. The schedule is a work queue of objects to serialize, and is held inside the formatter. If the object is already on the work queue, it will not be added a second time, but an exception will not be thrown either.
See also:
ObjectIDGenerator

Return to top


Method: Serialize(
   Stream serializationStream,
   object graph
)
Summary
When overridden in a derived class, serializes the graph of objects with the specified root to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
public abstract void Serialize(
   Stream serializationStream,
   object graph
);
Parameters:

serializationStream

The stream to which the objects are serialized.

graph

The object at the root of the graph to serialize.

Implements:
IFormatter.Serialize
Remarks


Notes to inheritors: You must implement this method in a derived class.
See also:
MSDN: serialization

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
This class is not CLS Compliant

C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: WriteArray(
   object obj,
   string name,
   Type memberType
)
Summary
When overridden in a derived class, writes an array to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteArray(
   object obj,
   string name,
   Type memberType
);
Parameters:

obj

The array to write.

name

The name of the array.

memberType

The type of elements that the array holds.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteBoolean(
   bool val,
   string name
)
Summary
When overridden in a derived class, writes a Boolean value to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteBoolean(
   bool val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteByte(
   byte val,
   string name
)
Summary
When overridden in a derived class, writes an 8-bit unsigned integer to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteByte(
   byte val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteChar(
   char val,
   string name
)
Summary
When overridden in a derived class, writes a Unicode character to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteChar(
   char val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteDateTime(
   DateTime val,
   string name
)
Summary
When overridden in a derived class, writes a DateTime value to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteDateTime(
   DateTime val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.
See also:
DateTime

Return to top


Method: WriteDecimal(
   decimal val,
   string name
)
Summary
When overridden in a derived class, writes a Decimal value to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteDecimal(
   decimal val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.
See also:
Decimal

Return to top


Method: WriteDouble(
   double val,
   string name
)
Summary
When overridden in a derived class, writes a double-precision floating-point number to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteDouble(
   double val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteInt16(
   short val,
   string name
)
Summary
When overridden in a derived class, writes a 16-bit signed integer to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteInt16(
   short val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteInt32(
   int val,
   string name
)
Summary
When overridden in a derived class, writes a 32-bit signed integer to the stream.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteInt32(
   int val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteInt64(
   long val,
   string name
)
Summary
When overridden in a derived class, writes a 64-bit signed integer to the stream.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteInt64(
   long val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteMember(
   string memberName,
   object data
)
Summary
Inspects the type of data received, and calls the appropriate Write method to perform the write to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected virtual void WriteMember(
   string memberName,
   object data
);
Parameters:

memberName

The name of the member to serialize.

data

The object to write to the stream attached to the formatter.

Remarks
To use this method properly, all the Write<DataType> methods ( Formatter.WriteArray method, Formatter.WriteBoolean method, Formatter.WriteByte method, and so on) should have the appropriate functionality.

Return to top


Method: WriteObjectRef(
   object obj,
   string name,
   Type memberType
)
Summary
When overridden in a derived class, writes an object reference to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteObjectRef(
   object obj,
   string name,
   Type memberType
);
Parameters:

obj

The object reference to write.

name

The name of the member.

memberType

The type of object the reference points to.

Remarks
Schedules the object with the graph walker to handle the work.

Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteSByte(
   sbyte val,
   string name
)
Summary
When overridden in a derived class, writes an 8-bit signed integer to the stream already attached to the formatter.
This class is not CLS Compliant

This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
protected abstract void WriteSByte(
   sbyte val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteSingle(
   float val,
   string name
)
Summary
When overridden in a derived class, writes a single-precision floating-point number to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteSingle(
   float val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteTimeSpan(
   TimeSpan val,
   string name
)
Summary
When overridden in a derived class, writes a TimeSpan value to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteTimeSpan(
   TimeSpan val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.
See also:
TimeSpan

Return to top


Method: WriteUInt16(
   ushort val,
   string name
)
Summary
When overridden in a derived class, writes a 16-bit unsigned integer to the stream already attached to the formatter.
This class is not CLS Compliant

This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
protected abstract void WriteUInt16(
   ushort val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteUInt32(
   uint val,
   string name
)
Summary
When overridden in a derived class, writes a 32-bit unsigned integer to the stream already attached to the formatter.
This class is not CLS Compliant

This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
protected abstract void WriteUInt32(
   uint val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteUInt64(
   ulong val,
   string name
)
Summary
When overridden in a derived class, writes a 64-bit unsigned integer to the stream already attached to the formatter.
This class is not CLS Compliant

This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
protected abstract void WriteUInt64(
   ulong val,
   string name
);
Parameters:

val

The value to write.

name

The name of the member.

Remarks


Notes to inheritors: You must implement this method in a derived class.

Return to top


Method: WriteValueType(
   object obj,
   string name,
   Type memberType
)
Summary
When overridden in a derived class, writes a value of the given type to the stream already attached to the formatter.
This class is not CLS Compliant

C# Syntax:
protected abstract void WriteValueType(
   object obj,
   string name,
   Type memberType
);
Parameters:

obj

The object representing the value type.

name

The name of the member.

memberType

The Type of the value type.

Remarks


Notes to inheritors: You must implement this method in a derived class.
See also:
ValueType

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.