System.Runtime.Serialization.FormatterServices Class

Assembly: Mscorlib.dll
Namespace: System.Runtime.Serialization
Summary
Provides static methods to aid with the implementation of a Formatter for serialization. This class cannot be inherited.
C# Syntax:
public sealed class FormatterServices
See also:
System.Runtime.Serialization Namespace | Formatter | MSDN: serialization

System.Runtime.Serialization.FormatterServices Member List:

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.
GetObjectData Extracts the data from the specified object and returns it as an array of objects.
GetSerializableMembers Overloaded:
GetSerializableMembers(Type type)

Gets all the serializable members for a class of the specified Type.
GetSerializableMembers Overloaded:
GetSerializableMembers(Type type, StreamingContext context)

Gets all the serializable members for a class of the specified Type and in the provided StreamingContext.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
GetTypeFromAssembly Looks up the Type of the specified object in the provided Assembly.
GetUninitializedObject Creates a new instance of the specified object type.
PopulateObjectMembers Populates the specified object with values for each field drawn from the data array of objects.
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.FormatterServices Member Details

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

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: GetObjectData(
   object obj,
   MemberInfo[] members
)
Summary
Extracts the data from the specified object and returns it as an array of objects.
C# Syntax:
public static object[] GetObjectData(
   object obj,
   MemberInfo[] members
);
Parameters:

obj

The object to write to the formatter.

members

The members to extract from the object.

Return Value:
An array of Object containing data stored in members and associated with obj.
Exceptions
Exception Type Condition
ArgumentNullException The obj or members parameter is null.

An element of members is null.

SerializationException An element of members does not represent a field.
Remarks
For each supplied member of the members array the FormatterServices.GetObjectData method extracts the value associated with the obj object, and returns it. The length of the returned array is the same as the length of the members array.
.NET Framework Security:
SecurityPermission for providing serialization services. Associated enumeration: SecurityPermissionFlag.SerializationFormatter.

Return to top


Overloaded Method: GetSerializableMembers(
   Type type
)
Summary
Gets all the serializable members for a class of the specified Type.
C# Syntax:
public static MemberInfo[] GetSerializableMembers(
   Type type
);
Parameters:

type

The type being serialized.

Return Value:
An array of type MemberInfo of the nontransient, nonstatic members.
Exceptions
Exception Type Condition
ArgumentNullException The type parameter is null.
Remarks
Generally, the serializable members of a class are the nontransient, nonstatic members such as fields and properties. To be included, properties must have both a getter and a setter. A class that implements the ISerializable interface or has a serialization surrogate does not have to serialize all these members, or can serialize additional members.
.NET Framework Security:
SecurityPermission for providing serialization services. Associated enumeration: SecurityPermissionFlag.SerializationFormatter.
See also:
MSDN: serialization | ISerializable | MemberInfo

Return to top


Overloaded Method: GetSerializableMembers(
   Type type,
   StreamingContext context
)
Summary
Gets all the serializable members for a class of the specified Type and in the provided StreamingContext.
C# Syntax:
public static MemberInfo[] GetSerializableMembers(
   Type type,
   StreamingContext context
);
Parameters:

type

The type being serialized or cloned.

context

The context where the serialization is occurring.

Return Value:
An array of type MemberInfo of the nontransient, nonstatic members.
Exceptions
Exception Type Condition
ArgumentNullException The type parameter is null.
Remarks
Generally, the serializable members of a class are the nontransient, nonstatic members such as fields and properties. To be included, properties must have both a getter and a setter. A class that implements ISerializable or has a serialization surrogate does not have to serialize all these members, or can serialize additional members.

Currently, you do not need to do anything different unless context has the StreamingContextStates value StreamingContextStates.Clone set.

.NET Framework Security:
SecurityPermission for providing serialization services. Associated enumeration: SecurityPermissionFlag.SerializationFormatter.
See also:
StreamingContext | MSDN: serialization | MemberInfo

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: GetTypeFromAssembly(
   Assembly assem,
   string name
)
Summary
Looks up the Type of the specified object in the provided Assembly.
C# Syntax:
public static Type GetTypeFromAssembly(
   Assembly assem,
   string name
);
Parameters:

assem

The assembly where you want to look up the object.

name

The name of the object.

Return Value:
The Type of the object.
Exceptions
Exception Type Condition
ArgumentNullException The assem parameter is null.
.NET Framework Security:
SecurityPermission for providing serialization services. Associated enumeration: SecurityPermissionFlag.SerializationFormatter.
.NET Framework Security:
ReflectionPermission for extraction of reflection information on members of a type that are not visible. Associated enumeration: ReflectionPermissionFlag.TypeInformation.
See also:
Assembly.GetType

Return to top


Method: GetUninitializedObject(
   Type type
)
Summary
Creates a new instance of the specified object type.
C# Syntax:
public static object GetUninitializedObject(
   Type type
);
Parameters:

type

The type of object to create.

Return Value:
A zeroed object of the specified type.
Exceptions
Exception Type Condition
ArgumentNullException The type parameter is null.
Remarks
Because the new instance of the object is initialized to zero and no constructors are run, the object might not represent a state that is regarded as valid by that object. The current method should only be used for deserialization when the user intends to immediately populate all fields. It will not create an uninitialized string, since creating an empty instance of an immutable type serves no purpose.
.NET Framework Security:
SecurityPermission for providing serialization services. Associated enumeration: SecurityPermissionFlag.SerializationFormatter.

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: PopulateObjectMembers(
   object obj,
   MemberInfo[] members,
   object[] data
)
Summary
Populates the specified object with values for each field drawn from the data array of objects.
C# Syntax:
public static object PopulateObjectMembers(
   object obj,
   MemberInfo[] members,
   object[] data
);
Parameters:

obj

The object to populate.

members

An array of MemberInfo describing which fields and properties to populate.

data

An array of Object specifying the values for each field and property to populate.

Return Value:
The newly populated object.
Exceptions
Exception Type Condition
ArgumentNullException The obj, members, or data parameter is null.

An element of members is null.

ArgumentException The length of members does not match the length of data.
SerializationException An element of members is not an instance of FieldInfo.
Remarks
If a matching surrogate for the object is found, then the populating is handed off to that surrogate. Otherwise, if the object implements ISerializable, the populating is handed off to the object itself. If a matching surrogate is not found, and the object does not implement the ISerializable interface, then deserialization populates each field listed in members, with the corresponding value listed in data.

If an element in data is null, FormatterServices.PopulateObjectMembers does not write anything to that field.

.NET Framework Security:
SecurityPermission for providing serialization services. Associated enumeration: SecurityPermissionFlag.SerializationFormatter.

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.