J
Joe Tavares
I have read several articles on serializing a singleton and have attempted
to implement it in my code. Unfortunately, the object is not being
serialized. The file size on disk is 1K. I am not sure exactly what I am
missing here, do I need to use AddValue to add the object fields I want to
serialize? None of the examples showed this. I can only assume it is
something basic since the overall pattern appears quite simple. I have
included a code snippet below which shows the pertinent parts.
Any help that anyone can supply would be very appreciated.
-joe-
[Serializable]
sealed public class Singleton: ISerializable
{
public static readonly Singleton Instance =
new Singleton ();
private List<cdmPendingCompoundObject> p_PendingCompoundObjects =
new List<cdmPendingCompoundObject>();
private String []p_FieldMaps;
private String[] p_DelimitedFields;
private String p_MetadataTitleNickName = "title";
void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext context)
{
info.SetType(typeof(SingletonSerializationHelper));
}
}
[Serializable]
internal class SingletonSerializationHelper : IObjectReference
{
public Object GetRealObject(StreamingContext context)
{
return Singleton.Instance;
}
}
to implement it in my code. Unfortunately, the object is not being
serialized. The file size on disk is 1K. I am not sure exactly what I am
missing here, do I need to use AddValue to add the object fields I want to
serialize? None of the examples showed this. I can only assume it is
something basic since the overall pattern appears quite simple. I have
included a code snippet below which shows the pertinent parts.
Any help that anyone can supply would be very appreciated.
-joe-
[Serializable]
sealed public class Singleton: ISerializable
{
public static readonly Singleton Instance =
new Singleton ();
private List<cdmPendingCompoundObject> p_PendingCompoundObjects =
new List<cdmPendingCompoundObject>();
private String []p_FieldMaps;
private String[] p_DelimitedFields;
private String p_MetadataTitleNickName = "title";
void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext context)
{
info.SetType(typeof(SingletonSerializationHelper));
}
}
[Serializable]
internal class SingletonSerializationHelper : IObjectReference
{
public Object GetRealObject(StreamingContext context)
{
return Singleton.Instance;
}
}