序列化 ComponentModel.Container?
是否可以序列化(二进制)System.ComponentModel.Container?
Is it possible to serialize (binary) a System.ComponentModel.Container?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,它没有标记为可序列化。
No, it is not marked serializable.
您实际上想在这里做什么?如前所述,除非类型可序列化,否则不能使用 BinaryFormatter,但您还需要考虑容器中可能包含的所有内容。它们还需要可序列化。
您可以通过不使用
BinaryFormatter
来解决“必须是[Serializing]
”问题,但大多数其他序列化程序(例如XmlSerializer
)都会有不预先知道所有子类以及诸如不可设置属性之类的问题。如果您有正确的 .NET 版本,您还可以考虑
XamlWriter
,这可能会提供一些有趣的可能性。What is it you actually want to do here? As has been noted, you can't use
BinaryFormatter
unless the type is serializable, but you would also need to consider all the things that might be contained in the container. They would also need to be serializable.You can get around the "must be
[Serializable]
" issue by not usingBinaryFormatter
, but most other serializers (for exampleXmlSerializer
) would have a problem with not knowing all the subclasses up-front, and things like non-settable properties.If you have the right .NET versions, you could also consider things like
XamlWriter
, which may provide some interesting possibilities.