I have a pretty sizeable object graph that I have serialized to a file via the DataContractSerializer. I now want to present a list of these files to the user to choose from. In this list, I want to show some of the details about the file, which are properties of the root object. I don't want to load the whole graph into memory, since I'm only interested in displaying properties of the root node.
Does anyone know a way to control the "depth" of the deserialization so that I can just pull the root object from the file and skip over the children? I'd rather avoid treating the file as raw XML, since I'm not doing any raw XML manipulations anywhere else, and that would be one more branch of code that I have to keep in sync.
My only idea right now is to create a compatible "summary" object containing only the properties I'm interested in, and none of the children, and deserialize the file into that. This should skip the children since they are not relevant to the summary object.
Is there a better way to accomplish this?
Update/Clarification: Attributes are not the answer I'm looking for. For one thing, they'll prevent the "extra" properties from ending up in the file when the object was first serialized.
Second, they're more permanent than what I'm trying to do. Eventually, I do want to deserialize the entire file, just not at this point. I'm trying to show a summary list of files that the user will choose from for import. During the import, I'm going to need all the children and grandchildren. It's just overkill during step 1. These are potentially large files, so fully deserializing several of them just so I can display their header information isn't going to work.
Hopefully that clears up any confusion about the original question.