I know of no serializers which serialize and deserialize event handlers and delegates. Think about it. How would a serializer know which object contains the event handler? Specific to the JSON (and XML) serializer/deserializer: How would it store that type information in JSON? How would a it know how to re-instantiate that object on deserialization if it doesn't know the type?
So yes, you would need to re-assign the event handlers.
How did you determine that the
particular instance of
MyTextSettings
and
MyVwapDaily
have been subscribed to twice?
Personally, I think it more likely that two event handlers were created, but they are subscribed to two different instances.
Theoretically somewhere in your code you have something like this because you didn't follow advice on post #8:
MyTextSettings = new TextSettings();
And you have either:
Case A:
MyTextSettings.Click += new EventHandler(Foo.OnClick);
or
Case B:
class TextSettings
{
public TextSettings()
{
Click += new EventHandler(Foo.OnClick);
}
}
And then later you have your code from post #21:
if (myContainer != null)
{
// The DeserializeObject() call below will create new instances of TextSettings
myContainer = JsonConvert.DeserializeObject<MyContainer>(_jsonFileRead, settings);
// Now you are pointing to that new instance:
MyTextSettings = myContainer.contTextSettings;
:
}
If you had case B, then as part of the calling the constructor for TextSettings, a new
Click
event handler will created.
If you had case A: you would need something like:
if (myContainer != null)
{
// The DeserializeObject() call below will create new instances of TextSettings
myContainer = JsonConvert.DeserializeObject<MyContainer>(_jsonFileRead, settings);
// Now you are pointing to that new instance:
MyTextSettings = myContainer.contTextSettings;
MyTextSettings.Click += new EventHandler(Foo.OnClick);
:
}
In both Case A and Case B, they will be new instances of
TextSettings
. They won't be the old instance you originally had when you first had:
MyTextSettings = new TextSettings();