Question

The ISerializable interface only provides a method to serialize the object. The deserialization process is managed by a constructor.

The problem is, that constructor cannot return an instance, because the constructor CREATES a new instance.

In my implementation, there are several attributes corresponding to singletons instantiated and maintainded somewhere else.

I need the deserialization process to get that instance and assign to the attribute, instead of creating a new instance.

The constructor approach is not suitable for this.

In Java, you would call the ReadResolve() method, is there a C# equivalent?

Was it helpful?

Solution

You need to make your classes which save a reference to the singleton implement IObjectReference.

Take a look at http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iobjectreference.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top