Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make an object serializable at runtime [closed]

Is there a way to make serializable an object at runtime? Should I use Reflection?

Note: the object is part of an external library, so I do not have the source code for it.

like image 943
Rick Avatar asked Oct 23 '25 14:10

Rick


1 Answers

tl;dr - No.

While you can use TypeDescriptor to add attributes to anything at runtime, in the context of the Serializable attribute it won't help since BinaryFormatter uses classic reflection and not TypeDesciptor reflection.

The idea behind that attribute is for the serializable class to opt-in to being serializable. More details about this here.

like image 69
Moti Azu Avatar answered Oct 26 '25 03:10

Moti Azu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!