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

  • SEARCH
  • Home
  • 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 677931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:05:36+00:00 2026-05-14T01:05:36+00:00

I need to mimic changes (property/list) changes on an object and then apply it

  • 0

I need to mimic changes (property/list) changes on an object and then apply it to another object to keep the structure/property the same.

In essence it’s like cloning etc. the biz rules require certain properties to not be applied to the other object, so I can’t just clone the object otherwise this would be easy.

I’ve already walked the source object to get INotifyPropertyChanged and IListChanged events, so I have the “source” and the args (Property or List) changed event notifications.

Given that I guess I could build a reflection “hierarchy path” starting from the top level of the source object to get to the Property or List changed “source” (which could be several levels deep).

Ignoring for the moment that certain object properties should not propagate to the other object, what’s a way to build this “path”? Is a brute force top level down to build the “path” (and discard on the way back up if we don’t hit the original changed event “source”) the only way to do it?

Any clever ideas on how to mimic changes from one object to another object?

  • 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-14T01:05:36+00:00Added an answer on May 14, 2026 at 1:05 am

    There are libraries available to make it easier (and faster) to work with reflection. For instance, Fasterflect allows you to write the following:

    // copy only the specified named properties
    source.MapProperties( target, "FirstName", "LastName" );
    

    From your description it sounds like you need something recursive though. I wrote a DeepClone method for Fasterflect, which I believe would make a good starting point for what you need. To adapt the code you’d need to modify it to (a) take a target object parameter instead of creating the instance internally, (b) get/set properties instead of fields and (c) accept a list of named properties to include.

    public static T DeepClone<T>( this T source ) where T : class, new()
    {
        return source.DeepClone( null );
    }
    

    Note the map parameter on the private method. This allows me to keep track of instances created (or in your case, visited) so that we can do the right thing when encountering cyclic references.

    private static T DeepClone<T>( this T source, Dictionary<object, object> map )
        where T : class, new()
    {
        Type type = source.GetType();
        IList<FieldInfo> fields = type.Fields( Flags.StaticInstanceAnyVisibility );
        var clone = type.CreateInstance() as T;
        map = map ?? new Dictionary<object, object>();
        map[ source ] = clone;
        object[] values = fields.Select( f => GetValue( f, source, map ) ).ToArray();
        for( int i = 0; i < fields.Count; i++ )
        {
            fields[ i ].Set( clone, values[ i ] );
        }
        return clone;
    }
    
    private static object GetValue( FieldInfo field, object source, Dictionary<object, object> map )
    {
        object result = field.Get( source );
        object clone;
        if( map.TryGetValue( result, out clone ) )
        {
            return clone;
        }
        bool follow = result != null && result.GetType().IsClass && result.GetType() != typeof(string);
        return follow ? result.DeepClone( map ) : result;
    }
    

    Note that the code uses other Fasterflect methods to speed up the actual reflection, but if you don’t want to depend on the library then this is easily replaceable.

    Disclaimer: I am involved in said project as a contributor.

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

Sidebar

Ask A Question

Stats

  • Questions 339k
  • Answers 339k
  • 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
  • Editorial Team
    Editorial Team added an answer Something like this: TableLayout table = (TableLayout)findViewById(R.id.table); LayoutInflater inflater =… May 14, 2026 at 4:26 am
  • Editorial Team
    Editorial Team added an answer Do these steps: Look for a a pattern such as… May 14, 2026 at 4:26 am
  • Editorial Team
    Editorial Team added an answer A quick and dirty way would be to have your… May 14, 2026 at 4:26 am

Related Questions

So a site I work on is migrating to a new data feed. The
In an application I'm building I had an enumeration of account statuses: public enum
I've been tasked with hooking in our product with another third party product. One
I work on a web application that modifies a XML document that is stored
i would like to program a little app that will change the colors of

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.