Export (0) Print
Expand All

FormatterServices.GetObjectData Method

Extracts the data from the specified object and returns it as an array of objects.

Namespace:  System.Runtime.Serialization
Assembly:  mscorlib (in mscorlib.dll)

static member GetObjectData : 
        obj:Object * 
        members:MemberInfo[] -> Object[] 

Parameters

obj
Type: System.Object

The object to write to the formatter.

members
Type: System.Reflection.MemberInfo[]

The members to extract from the object.

Return Value

Type: System.Object[]
An array of Object that contains data stored in members and associated with obj.

ExceptionCondition
ArgumentNullException

The obj or members parameter is a null reference (Nothing in Visual Basic).

An element of members is a null reference (Nothing in Visual Basic).

SerializationException

An element of members does not represent a field.

For each supplied member of the members array the 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.

The following example creates an instance of a Book class and sets field values on the instance. The code then gets the type information using the GetSerializableMembers method. The code copies the instance data into an object array using the GetObjectData method. A new uninitialized instance of the class is created using the GetSafeUninitializedObject method. Finally, the data from the first instance is copied into the second instance using the PopulateObjectMembers method.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft