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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:24:57+00:00 2026-05-26T21:24:57+00:00

I have some classes with lots of simple properties (from a datamodel I have

  • 0

I have some classes with lots of simple properties (from a datamodel I have no control over) — I’d like to be able to find if the new version of an object is the same as an old version, but don’t want to do 20 different “IsEqual” methods (I don’t really like the “IsEqual” name because it is not an analog to ==). Another wrinkle, in most of the cases I don’t want it to do a deep compare, but in some cases I do want that.

I’d like something along the lines of:

//Property could be PropertyInfo if that is necessary
bool IsEqual<T>(T first, T second, List<Property> ignorableProperties=emptyList, bool recurse=false)
{
    //the comparison code returning if they are equal ignoring 
    //the properties in the ignorableProperties list, recursing if recurse == true
    //not sure how I'd handle the comparison of sub-objects in the recursive step.
}
  • 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-26T21:24:58+00:00Added an answer on May 26, 2026 at 9:24 pm
    public static bool AreEqual<T>(this T first, T second, 
      bool recurse = false, params string[] propertiesToSkip)
    {
      if (Equals(first, second)) return true;
    
      if (first == null)
        return second == null;
      else if (second == null)
        return false;
    
      if (propertiesToSkip == null) propertiesToSkip = new string[] { };
      var properties = from t in first.GetType().GetProperties()
                       where t.CanRead
                       select t;
    
      foreach (var property in properties)
      {
        if (propertiesToSkip.Contains(property.Name)) continue;
    
        var v1 = property.GetValue(first, null);
        var v2 = property.GetValue(second, null);
    
        if (recurse)
          if (!AreEqual(v1, v2, true, propertiesToSkip))
            return false;
          else
            continue;
    
        if (!Equals(v1, v2)) return false;
      }
      return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a OCaml library with lots of classes I need some translator to
I have some classes(call it Class A) which I would like to unit test
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have some classes that are used for Styling and all of them display
I have some classes that represent immutable objects (Quantity, Price, Probability). Is there some
I have some classes which extends a superclass, and in the JSP I want
I have some classes that, for one reason or another, cannot be or need
I have some classes in my app that don't require an ID to be
I have some classes as below, i have implemented the Equals(Object) method for almost
I have some classes which are parameterized via their constructor. I need to provide

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.