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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:01:43+00:00 2026-06-15T03:01:43+00:00

Someone suggested using reflection for this. The method I have works great, but over

  • 0

Someone suggested using reflection for this. The method I have works great, but over 800,000 iterations, I came to the obvious conclusion (that most already came to) that reflection just doesn’t cut it.

Here’s part of my Helper class:

public static class Helper
{
    public static string[] ignoredProperties =
    { 
        "EntityState", 
        "EntityKey", 
        "Prop1", 
        "Prop2", 
        "Whatever", 
    };

    /// <summary>
    /// Check if properties of two objects are the same. Bypasses specified properties.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="first"></param>
    /// <param name="other"></param>
    /// <param name="ignoreProperties"></param>
    /// <returns></returns>
    public static bool PropertiesEquals<T>(this T first, T other, string[] ignoreProperties)
    {
        var propertyInfos = first.GetType().GetProperties();
        foreach (PropertyInfo propertyInfo in propertyInfos)
        {
            //Faster with custom method ? Nah...
            //if (FindElementIndex(ignoreProperties, propertyInfo.Name) < 0)

            //Probably faster if hardcoded.... Nah, not really either...
            //if (propertyInfo.Name != "EntityKey" && propertyInfo.Name != "EntityState" && propertyInfo.Name != "Group_ID" && propertyInfo.Name != "Import_status")

            if (Array.IndexOf(ignoreProperties, propertyInfo.Name) < 0)
                if (!Equals(propertyInfo.GetValue(first, null), propertyInfo.GetValue(other, null)))
                    return false;
        }
        return true;
    }

    public static int FindElementIndex(string[] input, string value)
    {
        int arraySize = input.Length - 1;
        Type valueType = value.GetType();

        for (int x = 0; x <= arraySize; x++)
        {
            if (input[x] == value)
                return x;
        }

        return -1;
    }

The problem is that those objects, depending on the type, can have up to 50 properties to check. So I can’t really do a bunch of ifs there.

Is there any way I could speed this up a bit?

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-06-15T03:01:44+00:00Added an answer on June 15, 2026 at 3:01 am

    Is there any way I could speed this up a bit ?

    Absolutely. If you’re going to fetch the same properties multiple times for different objects, create a delegate for each property (see this blog post I wrote a while ago for some examples) or use a project like Hyperdescriptor.

    (As of .NET 3.5, another way to create the delegate would be to use expression trees and compile them.)

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

Sidebar

Related Questions

I have a three tier set-up. Someone suggested I should get the ConnectionString from
All my research so far suggests this can't be done, but I'm hoping someone
I'm setting up a login system for a site and someone suggested using openID
So someone suggested using a WPF TreeView , and I thought: Yeah, that seems
I know this has been asked before but I have looked at every answer
I have been Googling for sometime but I guess I am using the wrong
Someone suggested moving a table full of settings, where each column is a setting
Can someone suggest what I am doing wrong? Basically I have a List Items,
This morning I asked a pretty mundane question about my JS syntax, and someone
I'm writing some code to parse a string into a double, but this string

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.