Is there any way to serialize a property with an internal setter in C#?
I understand that this might be problematic - but if there is a way - I would like to know.
Not that I've found without doing some work. I believe this is because the XmlSerializer
that is generated uses reflection to generate a new class (which is in a new assembly, so cannot see internal
member/methods).
There may be some mileage in using an XmlSerialization PreCompilier to generate the code, and then to modify it into an internal class for your purposes, so you'd then do something like:
XmlSerializer serializer = new MyPersonXmlSerializer();
The other option (and probably preferable) is to implement IXmlSerializable which will guide the auto-generated code to do the right thing.