Make an object serializable at runtime

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

Note: the object is part of an external library, so I don't have the source code for it.

+3


source to share


2 answers


tl; dr - No.

While you can use TypeDescriptor

to add attributes to anything at runtime, in the context of an attribute Serializable

it won't help as it BinaryFormatter

uses classic reflection, not TypeDesciptor

reflection.



The idea behind this attribute is that the class being serialized can be serializable. More on this here .

+3


source


Depending on the structure, you can use a serializer that doesn't pick, i.e. it does not require any attribute on the target class like XmlSerializer or JavaScriptSerializer .



0


source







All Articles