Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 101971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:52:25+00:00 2026-05-11T00:52:25+00:00

I have a pretty sizeable object graph that I have serialized to a file

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:52:26+00:00Added an answer on May 11, 2026 at 12:52 am

    That’s pretty much the way you want to do it. The DataContractSerializer is meant to handle this situation, where you have to types that are conceptually the same, but different types from the CLR’s point of view which you want to serialize into each other.

    Given that, just create the object with the similar subset of properties that you want to serialize and pass that type to the DataContractSerializer.

    Make sure that on the ‘summary’ type that you set the properties of the DataContract attribute (as well as any DataMember attributes or DataContract attributes on children you expose), specifically the Name and Namespace properties to reflect the name and namespace of the non-summary type (since these must match).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 52k
  • Answers 52k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The [R] modifier causes the response to be redirected to… May 11, 2026 at 6:35 am
  • added an answer Mono is somewhere between .NET 2.0 and .NET 3.5 See… May 11, 2026 at 6:35 am
  • added an answer Within one Test suite/class have a method public void TestForFooBehaviour(IFilter… May 11, 2026 at 6:35 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.