开发者

How to Serialize unserializable object in .NET

开发者 https://www.devze.com 2023-02-06 12:49 出处:网络
I have 3-rd party dll. From that I receive an object of some type (I know its interface, but not all the object). That object is not marked as serializable and I\'m not related to that libruary develo

I have 3-rd party dll. From that I receive an object of some type (I know its interface, but not all the object). That object is not marked as serializable and I'm not related to that libruary development at all.

I want to serialize it to some storage and then receive it from storage with the same state later (public/private, references etc.). I got here one option - make my own serialization mechanism that will act the same as开发者_运维问答 .NET serializers with the only difference - it won't revise serialization attributes.

Is that the best way?

Thanks.


You can use XmlSerializer or DataContractSerializer to serialize types not marked with SerializableAttribute.

There may be other options. And can always go ahead with custom implementation if nothing works for you.


You can make your own class inheriting from that object and serialize it.
OR you can make your own replica of that class and make some explicit (or implicit, but not recommended) conversion methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号