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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:11:09+00:00 2026-05-12T17:11:09+00:00

Just want to make simple extension for syntactic sygar : public static bool IsNotEmpty(this

  • 0

Just want to make simple extension for syntactic sygar :

public static bool IsNotEmpty(this ICollection obj)
{
    return ((obj != null)
        && (obj.Count > 0));
}

public static bool IsNotEmpty<T>(this ICollection<T> obj)
{
    return ((obj != null)
        && (obj.Count > 0));
}

It works perfectly when I work with some collections, but when working with others I get

The call is ambiguous between the
following methods or properties:
‘PowerOn.ExtensionsBasic.IsNotEmpty(System.Collections.IList)’
and
‘PowerOn.ExtensionsBasic.IsNotEmpty(System.Collections.Generic.ICollection)’

Is there any canonical solution to this problem ?

No, I don’t want to perform a cast before calling this method 😉

  • 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-12T17:11:09+00:00Added an answer on May 12, 2026 at 5:11 pm

    My best way to solve the ambiguity : define an overload for all common non-generic ICollection classes.
    That means custom ICollection won’t be compatible, but it’s no big deal as generics are becoming the norme.

    Here is the whole code :

    /// <summary>
    /// Check the given array is empty or not
    /// </summary>
    public static bool IsNotEmpty(this Array obj)
    {
        return ((obj != null)
            && (obj.Length > 0));
    }
    /// <summary>
    /// Check the given ArrayList is empty or not
    /// </summary>
    public static bool IsNotEmpty(this ArrayList obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    /// <summary>
    /// Check the given BitArray is empty or not
    /// </summary>
    public static bool IsNotEmpty(this BitArray obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    /// <summary>
    /// Check the given CollectionBase is empty or not
    /// </summary>
    public static bool IsNotEmpty(this CollectionBase obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    /// <summary>
    /// Check the given DictionaryBase is empty or not
    /// </summary>
    public static bool IsNotEmpty(this DictionaryBase obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    /// <summary>
    /// Check the given Hashtable is empty or not
    /// </summary>
    public static bool IsNotEmpty(this Hashtable obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    /// <summary>
    /// Check the given Queue is empty or not
    /// </summary>
    public static bool IsNotEmpty(this Queue obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    /// <summary>
    /// Check the given ReadOnlyCollectionBase is empty or not
    /// </summary>
    public static bool IsNotEmpty(this ReadOnlyCollectionBase obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    /// <summary>
    /// Check the given SortedList is empty or not
    /// </summary>
    public static bool IsNotEmpty(this SortedList obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    /// <summary>
    /// Check the given Stack is empty or not
    /// </summary>
    public static bool IsNotEmpty(this Stack obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    /// <summary>
    /// Check the given generic is empty or not
    /// </summary>
    public static bool IsNotEmpty<T>(this ICollection<T> obj)
    {
        return ((obj != null)
            && (obj.Count > 0));
    }
    

    Note that I did not want it to work on IEnumerable<T>, because Count() is a method that can trigger a database request if you are working with Linq-to-Entity or Linq-to-SQL.

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

Sidebar

Related Questions

I can't seem to find an answer on this and just want to make
Just wondering if you had any thoughts on this problem. I want to make
I am new to python, and just want to make a simple change. We
I had make a simple app into a facebook page and I just want
Hi I just want to make sure I have these concepts right. Overloading in
I just want to set a crontab using that I want to make a
i am done with my iphone application.Now i just want to make a binary
I am doing a md5 hash, and just want to make sure the result
I basically want to make things easier by just looping LinkButtons instead of making
This one very simple thing I can't find the right technique. What I want

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.