views:

559

answers:

1

I have a [Nonserialized] field in my class that is initialized inline:

[NonSerialized]
private bool running = true;

However, after deserializing an object I have running == false. This is not what I want. Can I force inline initializatin to work for all [NonSerialized] fields? Otherwise I will have to implement ISerializable...

+2  A: 

You could set it in the default constructor.

Implement the System.Runtime.Serialization.IDeserializationCallback

It is called afther the object is deserialized so you can perform your extra initialization there .

Stormenet
Does not work. As far as I understand, a class with [Serializable] attribute implicitly implements a constructor with a special signature that is called on deserialization.
Dmitry Risenberg
Ok, try the other solution :)
Stormenet
Thanks, this is exactly the thing I was looking for!
Dmitry Risenberg