T
Techno_Dex
I am trying to figure out what .NET does to a class that is marked as
Serializable in order to get the class to serialize. I know I can implement
the ISerializable interface, but I don't want to hand code all of the
classes that I have marked as Serializable, the standard .NET functionality
will work just fine for me, but I do want to know when the Serialization is
occuring in my class so I can handle the access of the public properties in
a different fashion. Can anyone explain to me what I need to put in the
ISerializable.GetObjectData() method to tell .NET to serialize as it
normally would?
[Serializable{}]
public partial class Test : ISerializable
{
private int List<CustomObject> mlCustomObjects = null;
private bool mbSerializingNow = false;
public List<CustomObject> CustomObjects
{
get
{
//I only want to instantiate the mlCustomObject List if it
is being requested by code, but not during the Serialization process.
if ((mlCustomObjects == null) && (mbSerializingNow ==
false))
{
mlCustomObjects = new List<CustomObject>();
}
return mlCustomObjects;
}
set { mlCustomObjects = value; }
}
public void GetObjectData (SerializationInfo info, StreamingContext
context)
{
mbSerializingNow = true;
//******************************************
// What do I do in here to get .NET to perform its standard
serialization???
//******************************************
mbSerializingNow = false;
}
}
Serializable in order to get the class to serialize. I know I can implement
the ISerializable interface, but I don't want to hand code all of the
classes that I have marked as Serializable, the standard .NET functionality
will work just fine for me, but I do want to know when the Serialization is
occuring in my class so I can handle the access of the public properties in
a different fashion. Can anyone explain to me what I need to put in the
ISerializable.GetObjectData() method to tell .NET to serialize as it
normally would?
[Serializable{}]
public partial class Test : ISerializable
{
private int List<CustomObject> mlCustomObjects = null;
private bool mbSerializingNow = false;
public List<CustomObject> CustomObjects
{
get
{
//I only want to instantiate the mlCustomObject List if it
is being requested by code, but not during the Serialization process.
if ((mlCustomObjects == null) && (mbSerializingNow ==
false))
{
mlCustomObjects = new List<CustomObject>();
}
return mlCustomObjects;
}
set { mlCustomObjects = value; }
}
public void GetObjectData (SerializationInfo info, StreamingContext
context)
{
mbSerializingNow = true;
//******************************************
// What do I do in here to get .NET to perform its standard
serialization???
//******************************************
mbSerializingNow = false;
}
}