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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:42:29+00:00 2026-06-13T13:42:29+00:00

I have been using resharper to generate my equality members, which has really helped

  • 0

I have been using resharper to generate my equality members, which has really helped with my unit testing.

However it doesn’t seem to work well when my object contains a list.

 public class FileandVersions
{

    public string fileName { get; set; }

    public string assetConfigurationType { get; set; }

    public List<Versions> Versions { get; set; }

    protected bool Equals(FileandVersions other)
    {
        return string.Equals(fileName, other.fileName) && string.Equals(assetConfigurationType, other.assetConfigurationType) && Equals(Versions, other.Versions);
    }

    public override bool Equals(object obj)
    {
        if (ReferenceEquals(null, obj)) return false;
        if (ReferenceEquals(this, obj)) return true;
        if (obj.GetType() != this.GetType()) return false;
        return Equals((FileandVersions) obj);
    }

    public override int GetHashCode()
    {
        unchecked
        {
            int hashCode = (fileName != null ? fileName.GetHashCode() : 0);
            hashCode = (hashCode*397) ^ (assetConfigurationType != null ? assetConfigurationType.GetHashCode() : 0);
            hashCode = (hashCode*397) ^ (Versions != null ? Versions.GetHashCode() : 0);
            return hashCode;
        }
    }
}

and here is the definition of the version object.

public class Versions
{

    public string versionNumber { get; set; }
    public DateTime acctivationTime { get; set; }
    public string URL { get; set; }

    protected bool Equals(Versions other)
    {
        return string.Equals(versionNumber, other.versionNumber) && acctivationTime.Equals(other.acctivationTime) && string.Equals(URL, other.URL);
    }

    public override bool Equals(object obj)
    {
        if (ReferenceEquals(null, obj)) return false;
        if (ReferenceEquals(this, obj)) return true;
        if (obj.GetType() != this.GetType()) return false;
        return Equals((Versions) obj);
    }

    public override int GetHashCode()
    {
        unchecked
        {
            int hashCode = (versionNumber != null ? versionNumber.GetHashCode() : 0);
            hashCode = (hashCode*397) ^ acctivationTime.GetHashCode();
            hashCode = (hashCode*397) ^ (URL != null ? URL.GetHashCode() : 0);
            return hashCode;
        }
    }
}

Comparison of these object are failing, even when the object are equivalent. Whats the best way to write equality members when the object contains a list?

  • 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-13T13:42:30+00:00Added an answer on June 13, 2026 at 1:42 pm

    You should replace the Equals(Versions, other.Versions) of the equality expression with this:

    ((Versions == null && other.Versions == null) || Versions != null && other.Versions != null && Versions.SequenceEqual(other.Versions))
    

    This expression is true when

    • Both Versions are null, or
    • Both Versions are not null, and they contain the same elements in the same order
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using TortoiseSVN for some time and I really like it. I
I have been using SDL with success to learn OpenGL, however I am following
I have been using git for 2 years now and love it. However, I
I have been using ReSharper for quite a long time and get used to
I have been using VS2010 with Resharper 5 for several weeks and am having
I have been renaming our model names in our codebase using resharper. I had
I have been using mySQL Quite a bit however, this is the first time
I have been using WPF for a new project which is far from done.
I have been using Stanford POS Tagger to tag parts of speech in a
I have been using play 1.2.5rc4 for development of one app and I have

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.