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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:21:47+00:00 2026-06-02T06:21:47+00:00

I have someone on GitHub asking for the ability to compare HashSets for my

  • 0

I have someone on GitHub asking for the ability to compare HashSets for my project on GitHub: https://github.com/GregFinzer/Compare-Net-Objects/. I need to be able to determine if a type is a hash set and then get the enumerator. I am not sure what to cast it to. Here is what I have for an IList:

private bool IsIList(Type type)
{
    return (typeof(IList).IsAssignableFrom(type));
}


private void CompareIList(object object1, object object2, string breadCrumb)
{
    IList ilist1 = object1 as IList;
    IList ilist2 = object2 as IList;

    if (ilist1 == null) //This should never happen, null check happens one level up
        throw new ArgumentNullException("object1");

    if (ilist2 == null) //This should never happen, null check happens one level up
        throw new ArgumentNullException("object2");

    try
    {
        _parents.Add(object1);
        _parents.Add(object2);

        //Objects must be the same length
        if (ilist1.Count != ilist2.Count)
        {
            Differences.Add(string.Format("object1{0}.Count != object2{0}.Count ({1},{2})", breadCrumb,
                                              ilist1.Count, ilist2.Count));

            if (Differences.Count >= MaxDifferences)
                return;
        }

        IEnumerator enumerator1 = ilist1.GetEnumerator();
        IEnumerator enumerator2 = ilist2.GetEnumerator();
        int count = 0;

        while (enumerator1.MoveNext() && enumerator2.MoveNext())
        {
            string currentBreadCrumb = AddBreadCrumb(breadCrumb, string.Empty, string.Empty, count);

            Compare(enumerator1.Current, enumerator2.Current, currentBreadCrumb);

            if (Differences.Count >= MaxDifferences)
                return;

            count++;
        }
    }
    finally
    {
        _parents.Remove(object1);
        _parents.Remove(object2);
    }
}
  • 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-02T06:21:50+00:00Added an answer on June 2, 2026 at 6:21 am

    I believe it is enough works directly with the ISet<T>, the ICollection<T> or the IEnumerable<T> generic interfaces instead of the HashSet<T>. You can detect these types using the following approach:

    // ...
        Type t = typeof(HashSet<int>);
        bool test1 = GenericClassifier.IsICollection(t); // true
        bool test2 = GenericClassifier.IsIEnumerable(t); // true
        bool test3 = GenericClassifier.IsISet(t); // true
    }
    //
    public static class GenericClassifier {
        public static bool IsICollection(Type type) {
            return Array.Exists(type.GetInterfaces(), IsGenericCollectionType);
        }
        public static bool IsIEnumerable(Type type) {
            return Array.Exists(type.GetInterfaces(), IsGenericEnumerableType);
        }
        public static bool IsISet(Type type) {
            return Array.Exists(type.GetInterfaces(), IsGenericSetType);
        }
        static bool IsGenericCollectionType(Type type) {
            return type.IsGenericType && (typeof(ICollection<>) == type.GetGenericTypeDefinition());
        }
        static bool IsGenericEnumerableType(Type type) {
            return type.IsGenericType && (typeof(IEnumerable<>) == type.GetGenericTypeDefinition());
        }
        static bool IsGenericSetType(Type type) {
            return type.IsGenericType && (typeof(ISet<>) == type.GetGenericTypeDefinition());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Someone have any sample of Comet app .net? I need one sample how to
Maybe someone that has experience with the Jquery Add to Calendar Widget (https://github.com/tardate/jquery.addtocalendar) can
In my app I am working with the SimpleKML framework https://github.com/mapbox/Simple-KML I have some
I have a PullRefreshTableView from leah(https://github.com/leah/PullToRefresh). Problem with this, as soon as I implement
maybe someone can help me: i'm using the rest server from here: https://github.com/philsturgeon/codeigniter-restserver .
https://github.com/JakeWharton/Android-ViewPagerIndicator I'm trying to include that library/project into my workspace, however nothing shows up
I have the relevant code posted in a gist: https://gist.github.com/1561520 I was wondering if
Can someone tell me what the difference is between the 2 JSON parsers? https://github.com/douglascrockford/JSON-js/blob/master/json.js
I have a grammar file — https://github.com/itrelease/fubar-script/blob/jsast/src/grammar.js but I get conflicts and I don't
Have someone used Typus (admin plugin for rails) in Heroku ? http://intraducibles.com/projects/typus/install I follow

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.