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 417599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:35:46+00:00 2026-05-12T18:35:46+00:00

I have a object graph that is setup like this Clients string Name List[Address]

  • 0

I have a object graph that is setup like this

Clients
    string Name
    List[Address] Addresses

I would like to cast this to

MyClients: Clients
    string Name
    List[MyAddress] Addresses

MyAddress: Address
    String City

I know that I can cast this by walking the whole object graph and in the given example that would not be to bad. But if you have a large object graph it gets hairy very fast and secondly it just seems plain wrong to have to walk the whole object graph.

I am looking for a solution that

  • Does not modify the Clients or Address objects
  • Does not walk the object graph
  • Can be implemented with very little code changes required.

    • 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. Editorial Team
      Editorial Team
      2026-05-12T18:35:46+00:00Added an answer on May 12, 2026 at 6:35 pm

      In a comment under your original question, you say:

      The reason for the cast is that the
      object graph starts in application A
      the object graph gets serialized and
      passed to appliaction B or application
      C. Appplication B and C extend the
      object graph for its own purposes.
      Application A is not aware of
      Application B or C or what Application
      B and C are doing to the object graph.
      Application B and C are vastly
      different applications

      And yet in the question you say a good solution:

      Does not modify the Clients or Address
      objects

      A cast isn’t able to add capabilities to an object. The object already has to have those capabilities.

      So it sounds like you don’t want to change the types, you just want to add extra facilities to those types within certain areas of your solution.

      So you need extension methods.

      You’d keep the types Client and Address, but add additional facilities via extension methods:

      public static class MyExtensions
      {
          public static void SendLetter(this Address address, string messageBody)
          {
              // blah
          }
      }
      

      This allows you to write:

      someClient.Addresses[0].SendLetter("Dear Sir, K THX BAI");
      

      You may need to store extra data along with each Address object. Probably the most convenient off-the-shelf solution to this is to make Address derive from DependencyObject, which allows you to stash extra data, using an instance of DependencyProperty as the key:

      public static class MyExtensionsWithData
      {
          // declare one of these for each "data slot" you'll be using
          public static readonly DependencyProperty PhoneProperty = 
              RegisterAttached("PhoneNumber", 
                               typeof(string), 
                               typeof(MyExtensionsWithData));
      
          public static void SetPhoneNumber(this Address address, string phone)
          {
              address.SetValue(PhoneProperty, phone);
          }
      
          public static string GetPhoneNumber(this Address address)
          {
              return (string)address.GetValue(PhoneProperty);
          }
      }
      

      This way, you can effectively add new properties to existing object, and can use them like this:

      // set
      someClient.Addresses[0].SetPhoneNumber("5550945793847");
      
      // get
      string phoneNum = someClient.Addresses[0].GetPhoneNumber();
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Ask A Question

    Stats

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

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

      • 7 Answers
    • Editorial Team

      What is a programmer’s life like?

      • 5 Answers
    • Editorial Team

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

      • 5 Answers
    • Editorial Team
      Editorial Team added an answer As dcneiner said the @ has been deprecated in the… May 13, 2026 at 12:59 am
    • Editorial Team
      Editorial Team added an answer On Linux systems and OS X, the character to input… May 13, 2026 at 12:59 am
    • Editorial Team
      Editorial Team added an answer Create a Base class for your pages and put your… May 13, 2026 at 12:59 am

    Related Questions

    Please forgive me if I don't explain this very well. First off, I am
    Object graph for type '[type]' contains cycles and cannot be serialized if reference tracking
    I have a setup where I am using amcharts that is feed data via
    I'm aiming to create a set of objects, each of which has a unique

    Trending Tags

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

    Top Members

    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.