Randy Minder
Randy Minder

Reputation: 48452

Serializing a private struct - Can it be done?

I have a public class that contains a private struct. The struct contains properties (mostly string) that I want to serialize. 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?

Upvotes: 0

Views: 486

Answers (1)

pstrjds
pstrjds

Reputation: 17438

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.

Upvotes: 1

Related Questions