FormatterServices.GetSerializableMembers Method (Type)


Gets all the serializable members for a class of the specified Type.

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

public static MemberInfo[] GetSerializableMembers(
	Type type


Type: System.Type

The type being serialized.

Return Value

Type: System.Reflection.MemberInfo[]

An array of type MemberInfo of the non-transient, non-static members.

Exception Condition

The type parameter is null.


The caller does not have the required permission.

Generally, the serializable members of a class are the non-transient, non-static 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.

The following code example demonstrates implementing the GetSerializableMembers method. This code example is part of a larger example provided for the FormatterServices class.

[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
public void GetObjectData(SerializationInfo info, StreamingContext context)

    // Serialize the desired values for this class.
    info.AddValue("title", title);

    // Get the set of serializable members for the class and base classes.
    Type thisType = this.GetType();
    MemberInfo[] mi = FormatterServices.GetSerializableMembers(thisType, context);

    // Serialize the base class's fields to the info object.
    for (Int32 i = 0; i < mi.Length; i++)
        // Do not serialize fields for this class.
        if (mi[i].DeclaringType == thisType) continue;

        // Skip this field if it is marked NonSerialized.
        if (Attribute.IsDefined(mi[i], typeof(NonSerializedAttribute))) continue;

        // Get the value of this field and add it to the SerializationInfo object.
        info.AddValue(mi[i].Name, ((FieldInfo) mi[i]).GetValue(this));

    // Call the method below to see the contents of the SerializationInfo object.


For providing serialization services. Associated enumeration: SecurityPermissionFlag.SerializationFormatter, SecurityAction.LinkDemand.

.NET Framework
Available since 1.1
Return to top