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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top