Serialize ComponentModel.Container?
Is it possible to serialize (bi开发者_Go百科nary) a System.ComponentModel.Container?
No, it is not marked serializable.
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 using BinaryFormatter
, but most other serializers (for example XmlSerializer
) 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.
精彩评论