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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:47:27+00:00 2026-05-19T04:47:27+00:00

I’m using an external library which returns an object array for the old state

  • 0

I’m using an external library which returns an object array for the old state and current state of an object (where each item in the array represents the properties and their values). So far i have come up with:

for (var i = 0; i < oldState.Length; i++) {
return oldState[i].Equals(state[i]);
}

This compares all the top level properties. But i also wish to drill into some (ones marked with the attribute CompareComplex) of the complex properties and compare for differences between it’s properties them aswell. I’d imagine the best way to achieve this would be to use a recursive function. I can’t quite get my head around this but i’m sure the solution is quite simple.

I’d really appreciate it if someone could help. Thanks

  • 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-19T04:47:27+00:00Added an answer on May 19, 2026 at 4:47 am

    cheers for your answers i have managed to come up the the following method:

    private bool Compare(Type type, string[] propertyNames, object[] oldState, object[] state) {
        // Get the property indexes to ignore
        var propertyIndexesToIgnore = type.GetProperties()
            .Where(p => p.GetCustomAttributes(typeof(IgnoreLoggingAttribute), false).Count() > 0)
            .Select(p => Array.IndexOf(propertyNames, p.Name)).ToArray();
    
        // Get the child property indexes
        var childPropertyIndexes = type.GetProperties()
            .Where(p => p.GetCustomAttributes(typeof(ChildLoggingAttribute), false).Count() > 0)
            .Select(p => Array.IndexOf(propertyNames, p.Name)).ToArray();
    
        for (var i = 0; i < oldState.Length; i++) {
            // If we need to check the child properties
            if (childPropertyIndexes.Contains(i)) {
                if (oldState[i] == null)
                    break;
    
                var childPropertyType = oldState[i].GetType();
                var childProperties = oldState[i].GetType().GetProperties();
    
                // Recursively call this function to check the child properties
                if (Compare(childPropertyType, childProperties.Select(p => p.Name).ToArray(), childProperties.Select(p => p.GetValue(oldState[i], null)).ToArray<object>(), childProperties.Select(p => p.GetValue(state[i], null)).ToArray<object>()))
                    return true;
            } else if (!propertyIndexesToIgnore.Contains(i) && ((oldState[i] != null && state[i] != null && !oldState[i].Equals(state[i])) || (oldState[i] != null && state[i] == null) || (oldState[i] == null && state[i] != null)))
                return true;
        }
    
        return false;
    }
    

    A few things to note:

    1. The amount of properties in my initial object array doesn’t match the number of items in type.GetProperties(). I can’t see how i can say whether an object within the object array has the IgnoreLogging attribute so i compare it against the type.
    2. The ChildLoggingAttribute is used to determine when an attribute is a complex type.

    If anyone has any suggestions on how i can improve this then i’d really appreciate it. Thanks

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but

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.