System.Runtime.Serialization.SerializationInfo Class

Assembly: Mscorlib.dll
Namespace: System.Runtime.Serialization
Summary
Holds all the data needed to serialize or deserialize an object. This class cannot be inherited.
C# Syntax:
public sealed class SerializationInfo
Remarks
This class is used by objects with custom serialization behavior. The ISerializable.GetObjectData method on either ISerializable or ISerializationSurrogate populates the SerializationInfo with the name, type, and value of each piece of information it wants to serialize. During deserialization, the appropriate function can extract this information.

Objects are added to the SerializationInfo at serialization time using the SerializationInfo.AddValue methods and extracted from the SerializationInfo at deserialization using the SerializationInfo.GetValue methods.

Example
The following code example demonstrates the SerializationInfo for custom serialization and deserialization of various values.
 using System;
 using System.IO;
 using System.Runtime.Serialization;
 using System.Runtime.Serialization.Formatters.Binary;
 
 namespace Testing 
 {
    public class Test {
       public static void Main(String[] args) {
       // Creates a new MyClass1 object.
          MyClass1 f = new MyClass1();
    
          // Opens a file and serializes the object into it in binary format.
          Stream stream = File.Open("MyClass1MyClass2.bin", FileMode.Create);
          BinaryFormatter bformatter = new BinaryFormatter();
 
          bformatter.Serialize(stream, f);
          stream.Close();
    
          //Empties f.
          f = null;
    
          //Opens file "MyClass1MyClass2.bin" and deserializes the MyClass1 object from it.
          stream = File.Open("MyClass1MyClass2.bin", FileMode.Open);
          bformatter = new BinaryFormatter();
          f = (MyClass1)bformatter.Deserialize(stream);
          stream.Close();
       }
    }
 

    [Serializable()] 
    public class MyClass1: ISerializable {

       public MyClass2 someObject;
       public int size;
       public String shape;

       //Default constructor
       public MyClass1() {
          someObject = new MyClass2();
       }
 
       //Deserialization constructor.
       public MyClass1 (SerializationInfo info, StreamingContext context) {
          size = (int)info.GetValue("size", typeof(int));
          shape = (String)info.GetValue("shape", typeof(string));

          //Allows MyClass2 to deserialize itself
          someObject = new MyClass2(info, context);
       }
 
       //Serialization function.
       public void GetObjectData(SerializationInfo info, StreamingContext context){
          info.AddValue("size", size);
          info.AddValue("shape", shape);

          //Allows MyClass2 to serialize itself
          someObject.GetObjectData(info, context);
       }
    }
 
    public class MyClass2 {
 
       public double value = 3.14159265;

       public MyClass2() {
       }

       public MyClass2(SerializationInfo info, StreamingContext context) {
           value = (double)info.GetValue("MyClass2_value", typeof(double));
       }

 
       public void GetObjectData(SerializationInfo info, StreamingContext context) {
          info.AddValue("MyClass2_value", value);
       }

    }
 }

    
See also:
System.Runtime.Serialization Namespace See also:
MSDN: serialization | ISerializable

System.Runtime.Serialization.SerializationInfo Member List:

Public Constructors
ctor #1 Creates a new instance of the SerializationInfo class.
Public Properties
AssemblyName Read-write

Gets or sets the assembly name of the type to serialize.
FullTypeName Read-write

Gets or sets the full name of the Type to serialize.
MemberCount Read-only

Gets the number of members that have been added to the SerializationInfo.
Public Methods
AddValue Overloaded:
AddValue(string name, bool value)

Adds a Boolean value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, byte value)

Adds an 8-bit unsigned integer value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, char value)

Adds a Unicode character value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, DateTime value)

Adds a DateTime value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, decimal value)

Adds a Decimal value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, double value)

Adds a double-precision floating-point value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, short value)

Adds a 16-bit signed integer value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, int value)

Adds a 32-bit signed integer value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, long value)

Adds a 64-bit signed integer value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, object value)

Adds the specified object into the SerializationInfo, where it is associated with a specified name.
AddValue Overloaded:
AddValue(string name, sbyte value)

Adds an 8-bit signed integer value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, float value)

Adds a single-precision floating-point value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, ushort value)

Adds a 16-bit unsigned integer value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, uint value)

Adds a 32-bit unsigned integer value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, ulong value)

Adds a 64-bit unsigned integer value into the SerializationInfo.
AddValue Overloaded:
AddValue(string name, object value, Type type)

Adds a value into the SerializationInfo, where value is associated with name and is serialized as being of Typetype.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetBoolean Retrieves a Boolean value from the SerializationInfo.
GetByte Retrieves an 8-bit unsigned integer value from the SerializationInfo.
GetChar Retrieves a Unicode character value from the SerializationInfo.
GetDateTime Retrieves a DateTime value from the SerializationInfo.
GetDecimal Retrieves a Decimal value from the SerializationInfo.
GetDouble Retrieves a double-precision floating-point value from the SerializationInfo.
GetEnumerator Returns a SerializationInfoEnumerator used to iterate through the name-value pairs in the SerializationInfo.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetInt16 Retrieves a 16-bit signed integer value from the SerializationInfo.
GetInt32 Retrieves a 32-bit signed integer value from the SerializationInfo.
GetInt64 Retrieves a 64-bit signed integer value from the SerializationInfo.
GetSByte Retrieves an 8-bit signed integer value from the SerializationInfo.
GetSingle Retrieves a single-precision floating-point value from the SerializationInfo.
GetString Retrieves a String value from the SerializationInfo.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
GetUInt16 Retrieves a 16-bit unsigned integer value from the SerializationInfo.
GetUInt32 Retrieves a 32-bit unsigned integer value from the SerializationInfo.
GetUInt64 Retrieves a 64-bit unsigned integer value from the SerializationInfo.
GetValue Retrieves a value from the SerializationInfo.
SetType Sets the Type of the object to serialize.
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.SerializationInfo Member Details

ctor #1
Summary
Creates a new instance of the SerializationInfo class.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public SerializationInfo(
   Type type,
   IFormatterConverter converter
);
Parameters:

type

The Type of the object to serialize.

converter

The IFormatterConverter used during deserialization.

Exceptions
Exception Type Condition
ArgumentNullException type or converter is null.
Remarks
The IFormatterConverter passed as the converter parameter converts data from its internal representation to the form the user requested. The internal representation of the data within the SerializationInfo depends on the formatter that created it.

Return to top


Property: AssemblyName (read-write)
Summary
Gets or sets the assembly name of the type to serialize.
C# Syntax:
public string AssemblyName {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The value the property is set to is null.
Remarks
The SerializationInfo.AssemblyName is the same as the value returned by Assembly.FullName property of the assembly of the containing type. This is the assembly name that the formatter uses when serializing type information for this object.

The assembly name contains the name of the assembly, version, culture, and some security information about the object. During deserialization, users who implemented ISerializable can compare the version of the assembly with the expected type to ensure that they are deserializing an expected version of the object.

Users who are changing the type being serialized (for example, to send a proxy for a particular type) will set the value of this property.

Return to top


Property: FullTypeName (read-write)
Summary
Gets or sets the full name of the Type to serialize.
C# Syntax:
public string FullTypeName {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The value this property is set to is null.
Remarks
The SerializationInfo.FullTypeName is the same as what would be returned by calling the Type.FullName on Type. This is the type name the formatter uses when serializing type information for this object.

Users who are changing the type to serialize (for example, to send a proxy for a particular type) will want to set the value of this property.

Return to top


Property: MemberCount (read-only)
Summary
Gets the number of members that have been added to the SerializationInfo.
C# Syntax:
public int MemberCount {get;}

Return to top


Overloaded Method: AddValue(
   string name,
   bool value
)
Summary
Adds a Boolean value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   bool value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The Boolean value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   byte value
)
Summary
Adds an 8-bit unsigned integer value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   byte value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The byte value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   char value
)
Summary
Adds a Unicode character value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   char value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The character value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   DateTime value
)
Summary
Adds a DateTime value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   DateTime value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The DateTime value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   decimal value
)
Summary
Adds a Decimal value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   decimal value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The Decimal value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException If The name parameter is null.
SerializationException If a value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   double value
)
Summary
Adds a double-precision floating-point value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   double value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The Double value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   short value
)
Summary
Adds a 16-bit signed integer value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   short value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The Int16 value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   int value
)
Summary
Adds a 32-bit signed integer value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   int value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The Int32 value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   long value
)
Summary
Adds a 64-bit signed integer value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   long value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The Int64 value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   object value
)
Summary
Adds the specified object into the SerializationInfo, where it is associated with a specified name.
C# Syntax:
public void AddValue(
   string name,
   object value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The value to be serialized. Any children of this object will automatically be serialized.

Exceptions
Exception Type Condition
ArgumentNullException name is null.
SerializationException A value has already been associated with name.
Remarks
The object contained in the value parameter is serialized as the type returned by value.GetType() or Object if value is null.

Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   sbyte value
)
Summary
Adds an 8-bit signed integer value into the SerializationInfo.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public void AddValue(
   string name,
   sbyte value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The Sbyte value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   float value
)
Summary
Adds a single-precision floating-point value into the SerializationInfo.
C# Syntax:
public void AddValue(
   string name,
   float value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The Single value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   ushort value
)
Summary
Adds a 16-bit unsigned integer value into the SerializationInfo.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public void AddValue(
   string name,
   ushort value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The UInt16 value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   uint value
)
Summary
Adds a 32-bit unsigned integer value into the SerializationInfo.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public void AddValue(
   string name,
   uint value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The UInt32 value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   ulong value
)
Summary
Adds a 64-bit unsigned integer value into the SerializationInfo.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public void AddValue(
   string name,
   ulong value
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The UInt64 value to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
SerializationException A value has already been associated with name.
Remarks
Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

Return to top


Overloaded Method: AddValue(
   string name,
   object value,
   Type type
)
Summary
Adds a value into the SerializationInfo, where value is associated with name and is serialized as being of Typetype.
C# Syntax:
public void AddValue(
   string name,
   object value,
   Type type
);
Parameters:

name

The name to associate with the value, so it can be deserialized later.

value

The value to be serialized. Any children of this object will automatically be serialized.

type

The Type to associate with the current object. This parameter must always be the type of the object itself or of one of its base classes.

Exceptions
Exception Type Condition
ArgumentNullException If name or type is null.
SerializationException A value has already been associated with name.
Remarks
The assigned type is always the type of the object, or one of its parents.

Trying to add the same name twice into the SerializationInfo is an error. The names are compared using an ordinal comparison, so it is possible, but not advisable, to have two names that differ only by case.

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:
~SerializationInfo();

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

Return to top


Method: GetBoolean(
   string name
)
Summary
Retrieves a Boolean value from the SerializationInfo.
C# Syntax:
public bool GetBoolean(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The Boolean value associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to a Boolean value.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a Boolean, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetByte(
   string name
)
Summary
Retrieves an 8-bit unsigned integer value from the SerializationInfo.
C# Syntax:
public byte GetByte(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The 8-bit unsigned integer associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to an 8-bit unsigned integer.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is an 8-bit unsigned integer, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetChar(
   string name
)
Summary
Retrieves a Unicode character value from the SerializationInfo.
C# Syntax:
public char GetChar(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The Unicode character associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to a Unicode character.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a Unicode character, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetDateTime(
   string name
)
Summary
Retrieves a DateTime value from the SerializationInfo.
C# Syntax:
public DateTime GetDateTime(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The DateTime value associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to a DateTime value.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a DateTime, or can be converted to a DateTime, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetDecimal(
   string name
)
Summary
Retrieves a Decimal value from the SerializationInfo.
C# Syntax:
public decimal GetDecimal(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
A Decimal value from the SerializationInfo.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to a Decimal.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a Decimal, or can be converted to a Decimal, that value is returned; otherwise an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetDouble(
   string name
)
Summary
Retrieves a double-precision floating-point value from the SerializationInfo.
C# Syntax:
public double GetDouble(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The double-precision floating-point value associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to a double-precision floating-point value.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a Double, or can be converted to a Double, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetEnumerator()
Summary
Returns a SerializationInfoEnumerator used to iterate through the name-value pairs in the SerializationInfo.
C# Syntax:
public SerializationInfoEnumerator GetEnumerator();
Return Value:
A SerializationInfoEnumerator for parsing the name-value pairs in this SerializationInfo.
Remarks
This function will most often be used by formatters that need to enumerate through the values before writing them out to the stream.

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: GetInt16(
   string name
)
Summary
Retrieves a 16-bit signed integer value from the SerializationInfo.
C# Syntax:
public short GetInt16(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The 16-bit signed integer associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to an 16-bit signed integer.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a 16-bit signed integer, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetInt32(
   string name
)
Summary
Retrieves a 32-bit signed integer value from the SerializationInfo.
C# Syntax:
public int GetInt32(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The 32-bit signed integer associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to an 32-bit signed integer.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a 32-bit signed integer, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetInt64(
   string name
)
Summary
Retrieves a 64-bit signed integer value from the SerializationInfo.
C# Syntax:
public long GetInt64(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The 64-bit signed integer associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to an 64-bit signed integer.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a 64-bit signed integer, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetSByte(
   string name
)
Summary
Retrieves an 8-bit signed integer value from the SerializationInfo.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public sbyte GetSByte(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The 8-bit signed integer associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to an 8-bit signed integer.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is an Int8, or can be converted to an Int8, that value is returned; otherwise an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetSingle(
   string name
)
Summary
Retrieves a single-precision floating-point value from the SerializationInfo.
C# Syntax:
public float GetSingle(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The single-precision floating-point value associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to a single-precision floating-point value.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a single-precision floating-point number, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetString(
   string name
)
Summary
Retrieves a String value from the SerializationInfo.
C# Syntax:
public string GetString(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The String associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to a String.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a String, or can be converted to a String, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

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: GetUInt16(
   string name
)
Summary
Retrieves a 16-bit unsigned integer value from the SerializationInfo.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public ushort GetUInt16(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The 16-bit unsigned integer associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to an 16-bit unsigned integer.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a 16-bit unsigned integer, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetUInt32(
   string name
)
Summary
Retrieves a 32-bit unsigned integer value from the SerializationInfo.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public uint GetUInt32(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The 32-bit unsigned integer associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to an 32-bit unsigned integer.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a 32-bit signed integer, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetUInt64(
   string name
)
Summary
Retrieves a 64-bit unsigned integer value from the SerializationInfo.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public ulong GetUInt64(
   string name
);
Parameters:

name

The name of the value to retrieve.

Return Value:
The 64-bit unsigned integer associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name is null.
InvalidCastException The value associated with name cannot be converted to an 64-bit unsigned integer.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the value is a 64-bit unsigned integer, or can be converted to one, that value is returned; otherwise, an InvalidCastException is thrown. All conversions are done by the IFormatterConverter associated with this SerializationInfo.

Return to top


Method: GetValue(
   string name,
   Type type
)
Summary
Retrieves a value from the SerializationInfo.
C# Syntax:
public object GetValue(
   string name,
   Type type
);
Parameters:

name

The name of the value to retrieve.

type

The type of the value to retrieve. If the stored value cannot be converted to this type, the system will throw an InvalidCastException.

Return Value:
The object of the specified Type associated with name.
Exceptions
Exception Type Condition
ArgumentNullException name or type is null.
InvalidCastException The value associated with name cannot be converted to type.
SerializationException An element with the specified name is not found in the current instance.
Remarks
If the data stored in the SerializationInfo is of the type requested (or one of its derived classes), that value is returned directly. Otherwise, IFormatterConverter.Convert is called to convert it to the appropriate type.

Note The value returned by the SerializationInfo.GetValue method can always be safely cast to the type specified in the type parameter.
Example
The following code example demonstrates the use of the SerializationInfo.GetValue method:
// A serializable LinkedList example.  For the full LinkedList implementation
// see the Serialization sample in the .NET Framework SDK.
[Serializable()]
class LinkedList: ISerializable {

   public static void Main() {}

   Node m_head = null;
   Node m_tail = null;
   
   // Serializes the object.
   public void GetObjectData(SerializationInfo info, StreamingContext context){
      // Stores the m_head and m_tail references in the SerializationInfo info.
      info.AddValue("head", m_head, m_head.GetType());
      info.AddValue("tail", m_tail, m_tail.GetType());
   }
   
   // Constructor that is called automatically during deserialization.
   // Reconstructs the object from the information in SerializationInfo info
   private LinkedList(SerializationInfo info, StreamingContext context){      
      Node temp = new Node(0);
      // Retrieves the values of Type temp.GetType() from SerializationInfo info
      m_head = (Node)info.GetValue("head", temp.GetType());
      m_tail = (Node)info.GetValue("tail", temp.GetType());
   }
}

    

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: SetType(
   Type type
)
Summary
Sets the Type of the object to serialize.
C# Syntax:
public void SetType(
   Type type
);
Parameters:

type

The Type of the object to serialize.

Exceptions
Exception Type Condition
ArgumentNullException The type parameter is null.
Remarks
The Formatter is responsible for setting the Type of the SerializationInfo before passing it to ISerializable.GetObjectData. However, users who want to send proxies for their objects will need to change the type represented by this SerializationInfo. Using the SerializationInfo.SetType method is equivalent to setting both the SerializationInfo.FullTypeName and the SerializationInfo.AssemblyName.

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.