Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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.</p> <p>Here is the whole code :</p> <pre><code>/// &lt;summary&gt; /// Check the given array is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this Array obj) { return ((obj != null) &amp;&amp; (obj.Length &gt; 0)); } /// &lt;summary&gt; /// Check the given ArrayList is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this ArrayList obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } /// &lt;summary&gt; /// Check the given BitArray is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this BitArray obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } /// &lt;summary&gt; /// Check the given CollectionBase is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this CollectionBase obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } /// &lt;summary&gt; /// Check the given DictionaryBase is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this DictionaryBase obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } /// &lt;summary&gt; /// Check the given Hashtable is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this Hashtable obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } /// &lt;summary&gt; /// Check the given Queue is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this Queue obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } /// &lt;summary&gt; /// Check the given ReadOnlyCollectionBase is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this ReadOnlyCollectionBase obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } /// &lt;summary&gt; /// Check the given SortedList is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this SortedList obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } /// &lt;summary&gt; /// Check the given Stack is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty(this Stack obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } /// &lt;summary&gt; /// Check the given generic is empty or not /// &lt;/summary&gt; public static bool IsNotEmpty&lt;T&gt;(this ICollection&lt;T&gt; obj) { return ((obj != null) &amp;&amp; (obj.Count &gt; 0)); } </code></pre> <p>Note that I did not want it to work on <code>IEnumerable&lt;T&gt;</code>, because <code>Count()</code> is a method that can trigger a database request if you are working with Linq-to-Entity or Linq-to-SQL.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload