I've been pretty confused on one point in design of DataContracts for serialization.
Say I have an object (e.g. a Customer) and it exposes a collection property (e.g. an AddressCollection named Addresses). Framework design guidelines dictate that I should not expose a public mutator for the property, i.e., the collection property should have a get and no set, and instead a public set method (public void SetAddresses(IEnumerable< Address> addresses)).
But if I want to serialize that object, and I anticipate that I will be in a partial-trust environment, do I have to add a public setter to the property so it can be properly deserialized?
Furthermore, if the collection has nothing in it on serialization, and since the default constructor isn't called by the DataContractSerializer, I'm pretty sure the collection isn't set at all and is left as null. I could use the OnSerializing attribute to initialize the collection, but then that method would also have to be public in a partial-trust scenario, wouldn't it? And that's even uglier.
Does anyone know the appropriate guidance here?
Thanks much.