Deserializing object

  • Thread starter Thread starter Søren M. Olesen
  • Start date Start date
S

Søren M. Olesen

Hi

Is there any way (at all) that an object beign deserialized from a stream
can know (or figure out) that it has been created because of a deserialize
process rather than by a "normal" object instiantiation ??


TIA

Søren
 
Is there any way (at all) that an object beign deserialized from a
stream can know (or figure out) that it has been created because of a
deserialize process rather than by a "normal" object instiantiation ??

Maybe u can create a property "IsDeserialized" and flag the object during
deserialization?
 
Søren M. Olesen ha scritto:
Hi

Is there any way (at all) that an object beign deserialized from a stream
can know (or figure out) that it has been created because of a deserialize
process rather than by a "normal" object instiantiation ??

How about this :

<Serializable()> Class YourObject

<nonserialized()> Public HasBeenNormallyInstantiated As Boolean =
True

'Other properties ...

End Class

the flag HasBeenNormallyInstantiated will hold the answer because when
deserialized will be false. Will be true when YourObject "normally"
instantiated.
 
Søren M. Olesen said:
Hi

Is there any way (at all) that an object beign deserialized from a stream
can know (or figure out) that it has been created because of a deserialize
process rather than by a "normal" object instiantiation ??


TIA

Søren

Well yes... If you implement the ISerializable interface, then you
will have to add a constructor like:

Public Sub New (ByVal info As SerializationInfo, ByVal context As
StreamingContext)

This constructor will be called when the object is deserialized.
 
Back
Top