Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does [Serializable] work for inherited classes?

I haven't worked much with remoting so excuse this rather rudimentary question, If I derive a class from an abstract class marked as [Serializable] (for passing the data across an appdomain), does the other side get the actual overriden implementation? ie does polymorphism work over remoting/Serializable?

I need to create a clone on the other side rather than operating on the original so MarshalByRef is not an option...

like image 614
Homde Avatar asked Jan 05 '11 23:01

Homde


2 Answers

The easiest way to see that [Serializable] is not inherited is press F12 and see "Inherited = false" in AttributeUsage. The harder option is to RTFM at http://msdn.microsoft.com/en-us/library/bcfsa90a.aspx .

Essentially you need to mark all you classes as serializable and they will be deserialized properly.

like image 114
Alexei Levenkov Avatar answered Oct 12 '22 02:10

Alexei Levenkov


Yes when you deserialize a type, the same type is reconstituted in the remote domain.

You can control the deserialized type by using the IObjectReference pattern:

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

like image 2
csharptest.net Avatar answered Oct 12 '22 02:10

csharptest.net