开发者

Serializing a private struct - Can it be done?

开发者 https://www.devze.com 2023-02-07 07:17 出处:网络
I have a public class that contains a private struct. The struct contains properties (mostly string) that I want to seria开发者_开发问答lize. When I attempt to serialize the struct and stream it to di

I have a public class that contains a private struct. The struct contains properties (mostly string) that I want to seria开发者_开发问答lize. When I attempt to serialize the struct and stream it to disk, using XmlSerializer, I get an error saying only public types can be serialized. I don't need, and don't want, this struct to be public. Is there a way I can serialize it and keep it private?


I believe if you implement IXmlSerializable then you should be able to control exactly what and how the data is serialized. If you look at the example in the provided link, they serialize a private string.

0

精彩评论

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