使对象在运行时可序列化

编程入门 行业动态 更新时间:2024-10-28 10:35:16
本文介绍了使对象在运行时可序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有一种方法可以在运行时使对象可序列化?我应该使用反射吗?

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.

推荐答案

tl; dr-否

虽然可以在运行时使用 TypeDescriptor 向任何内容添加属性,但是在 Serializable 属性的上下文中,由于 BinaryFormatter 使用经典反射,而不使用 TypeDesciptor 反射.

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.

更多推荐

使对象在运行时可序列化

本文发布于:2023-11-09 20:09:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573304.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   序列化

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!