I have a few classes (about 15 or so) in VB.net (2005) that I would like to be able to serialize to xml. Unfortunately they are labeled as friend classes and cannot be exposed outside of the assembly.
The assembly is a dll that is a com interop plugin to a CAD system. I have set all of my classes as friends so that they are not exposed outside of the assembly for 3rd party use. I am wondering if I even need to do that. Setting the class to public would allow me to serialize things. However I don’t want people linking to the assembly and using the classes.
Should I even worry about other programs linking to my assembly? In fact I don’t think there is a large chance of this happening. I just don’t like the idea of having almost all of my classes with a public scope.
Is there a way to make a friend class serializable? Or should I just make things public?
Cheers,
Troy
This “protection” won’t work anyway. People can load your assembly with reflection and then use the classes. So that reason to not make the classes public vanishes, which simplifies things.
If you really want to keep your classes internal, you can still either write your own serialization code (completely manually (efficient, but much work required) or with reflection), or you can provide separate data-only classes for serialization purposes only, which can be made public. Then you just have to write code that imports/exports the data in your internal classes to the serialization classes, and the classes won’t be of much use to other developers since the actual code is in the internal classes.