Custom Object collection Serialization-Collection of common programming errors
I’m attempting to Serialize my custom collection UserDataCollection, made out of UserData objects. I wondered when implementing Serialization, does the actual object (UserData) also need have the attribute [Serializable] and inherit from the ISerializable interface?
I want to serialize each object (UserData) in the collection, all it’s properties and variables.
I have this at the moment:
public class UserData : IEquatable, IUser
{
/// some properties methods
}
[Serializable()]
class UserDataCollection : IEnumerable, ISerializable
{
static List Collection = new List();
IUser current;
#region Properties
public UserData Current
{
get
{
return (UserData)current;
}
set
{
current = value;
}
}
#endregion
#region Constructors
public UserDataCollection( IUser userdata )
{
this.current = userdata;
}
///
/// Deserialization Constructor
///
/// This object holds a name-value pair for the properties to be serialized
///
public UserDataCollection(SerializationInfo serializationInfo, StreamingContext ctxt)
{
Current = (UserData)serializationInfo.GetValue("UserData", typeof(UserData));