I'm converting some of my classes to use DataContractSerialization so that I can include Linq Entities in the output. A sort of theoretical question popped into my head while I was in the process, and while I'm betting the answer is "No" I figured I'd pose the question anyway.
Is there a way to conditionally serialize an object? For instance if I'm serializing an Employee object with the intention to send information to a customer I might not want to include the address. On the other hand if I'm serializing it to use in a web service for the site that manages that employee I might need that info.
Another possibility would be serializing certain members based on whether they were the base object being serialized or not. So if I have a Ticket class which contains a Location, and the Location contains a list of Contacts I probably wouldn't want that contacts list if I were serializing the Ticket. But if I were trying to work with the Location itself, it might be good to have.
So any thoughts on that?