R
Robert Hooker
Given a class:
[Serializable]
public class MyClass : ISerializable
{
//
//Lots of fields and members
//
public void GetObjectData(SerializationInfo info, StreamingContext
context)
{
MemberInfo[] arMI =
FormatterServices.GetSerializableMembers(this.GetType(),context);
foreach ( MemberInfo mi in arMI )
{
info.AddValue( mi.Name,((FieldInfo)mi).GetValue(obj) );
}
}
}
I can serialize a collection of 10000 "MyClass" no problems. Takes about 2
seconds or so with a BinaryFormatter.
If I remove the "ISerializable" inheritence and serialize the collection, it
takes about half the time - around 1 second.
My Question:
I ask because, most of the time, I want the ISerializable implementation
(for change-tolerance during deserialization) but for some other 'non
persistence' operations I want a fast serialization (for deep copies and for
"undo redo" snapshots of object graphs)
Any help is greatly appreciated!
Rob.
[Serializable]
public class MyClass : ISerializable
{
//
//Lots of fields and members
//
public void GetObjectData(SerializationInfo info, StreamingContext
context)
{
MemberInfo[] arMI =
FormatterServices.GetSerializableMembers(this.GetType(),context);
foreach ( MemberInfo mi in arMI )
{
info.AddValue( mi.Name,((FieldInfo)mi).GetValue(obj) );
}
}
}
I can serialize a collection of 10000 "MyClass" no problems. Takes about 2
seconds or so with a BinaryFormatter.
If I remove the "ISerializable" inheritence and serialize the collection, it
takes about half the time - around 1 second.
My Question:
I ask because, most of the time, I want the ISerializable implementation
(for change-tolerance during deserialization) but for some other 'non
persistence' operations I want a fast serialization (for deep copies and for
"undo redo" snapshots of object graphs)
Any help is greatly appreciated!
Rob.