public sealed class SerializationInfo
|
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.
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); } } }
ctor #1 | Creates a new instance of the SerializationInfo class. |
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. |
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. |
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:
[CLSCompliant(false)] |
type
converter
Exception Type | Condition |
---|---|
ArgumentNullException | type or converter is null. |
public string AssemblyName {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The value the property is set to is null. |
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.
public string FullTypeName {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The value this property is set to is null. |
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.
public int MemberCount {get;}
|
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | If The name parameter is null. |
SerializationException | If a value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | name is null. |
SerializationException | A value has already been associated with name. |
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.
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
SerializationException | A value has already been associated with name. |
name
value
type
Exception Type | Condition |
---|---|
ArgumentNullException | If name or type is null. |
SerializationException | A value has already been associated with name. |
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.
~SerializationInfo(); |
name
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. |
name
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. |
name
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. |
name
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. |
name
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. |
name
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. |
public SerializationInfoEnumerator GetEnumerator(); |
public virtual int GetHashCode(); |
name
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. |
name
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. |
name
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. |
name
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. |
name
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. |
name
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. |
public Type GetType(); |
name
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. |
name
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. |
name
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. |
name
type
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. |
// 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()); } }
protected object MemberwiseClone(); |
public void SetType( |
type
Exception Type | Condition |
---|---|
ArgumentNullException | The type parameter is null. |
public virtual string ToString(); |