System.Runtime.Serialization.ObjectIDGenerator Class

Assembly: Mscorlib.dll
Namespace: System.Runtime.Serialization
Summary
Generates IDs for objects.
C# Syntax:
[Serializable]
public class ObjectIDGenerator
Remarks
The ObjectIDGenerator keeps track of previously identified objects. When you ask for the ID of an object, the ObjectIDGenerator knows whether to return the existing ID, or generate and remember a new ID.

The IDs are unique for the life of the ObjectIDGenerator instance. Generally, an ObjectIDGenerator life lasts as long as the Formatter that created it. Object IDs have meaning only within a given serialized stream, and are used for tracking which objects have references to others within the serialized object graph.

Using a hash table, the ObjectIDGenerator retains what ID is assigned to what object. The object references, which uniquely identify each object, are addresses in the runtime garbage-collected heap. Object reference values can change during serialization, but the table is updated automatically so the information is correct.



Note Object IDs are 64-bit numbers. Allocation starts from one, so zero is never a valid object ID. A formatter can choose a zero value to represent an object reference whose value is null.
See also:
System.Runtime.Serialization Namespace See also:
MSDN: serialization | Formatter

System.Runtime.Serialization.ObjectIDGenerator Member List:

Public 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 ObjectIDGenerator class.
Public Methods
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.
GetId Returns the ID for the specified object, generating a new ID if the specified object has not already been identified by the ObjectIDGenerator.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
HasId Determines whether an object has already been assigned an ID.
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 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.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Runtime.Serialization.ObjectIDGenerator Member Details

ctor #1
Summary
Initializes a new instance of the ObjectIDGenerator class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public ObjectIDGenerator();

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
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
C# Syntax:
~ObjectIDGenerator();

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
C# Syntax:
public virtual int GetHashCode();

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

Return to top


Method: GetId(
   object obj,
   out bool firstTime
)
Summary
Returns the ID for the specified object, generating a new ID if the specified object has not already been identified by the ObjectIDGenerator.
C# Syntax:
public virtual long GetId(
   object obj,
   out bool firstTime
);
Parameters:

obj

The object you want an ID for.

firstTime

true if obj was not previously known to the ObjectIDGenerator; otherwise, false.

Return Value:
The object's ID is used for serialization.firstTime is set to true if this is the first time the object has been identified; otherwise, it is set to false.
Exceptions
Exception Type Condition
ArgumentNullException The obj parameter is null.
SerializationException The ObjectIDGenerator has been asked to keep track of too many objects.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

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

Return to top


Method: HasId(
   object obj,
   out bool firstTime
)
Summary
Determines whether an object has already been assigned an ID.
C# Syntax:
public virtual long HasId(
   object obj,
   out bool firstTime
);
Parameters:

obj

The object you are asking for.

firstTime

true if obj was not previously known to the ObjectIDGenerator; false otherwise.

Return Value:
The object ID of obj if previously known to the ObjectIDGenerator, otherwise, zero.
Exceptions
Exception Type Condition
ArgumentNullException The obj parameter is null.
Remarks
If the object has already been assigned an ID, the ID is returned and firstTime is set to false; otherwise, zero is returned and firstTime is set to true. ObjectIDGenerator.HasId differs from ObjectIDGenerator.GetId in that it never creates an ID for an object that has not already been seen by the ObjectIDGenerator.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

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

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

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

Return to top


Top of page

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