1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
namespace CKing.Extensions
{
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Contains basic extension-methods, like 'IsNull', 'IsNullOrEmpty', aso.
/// </summary>
public static class BasicExt
{
/// <summary>
/// Determines whether the object is null.
/// </summary>
/// <param name="source">The object, which may be null.</param>
/// <returns>
/// <c>true</c> if the object is null; otherwise, <c>false</c>.
/// </returns>
public static bool IsNull(this object source)
{
return source == null;
}
/// <summary>
/// Determines whether the string is null or contains no chars.
/// </summary>
/// <param name="source">The string, which may be null or empty.</param>
/// <returns>
/// <c>true</c> if the string is null or empty; otherwise, <c>false</c>.
/// </returns>
public static bool IsNullOrEmpty(this string source)
{
return string.IsNullOrEmpty(source);
}
/// <summary>
/// Determines whether the collection is null or contains no elements.
/// </summary>
/// <typeparam name="T">The IEnumerable type.</typeparam>
/// <param name="source">The enumerable, which may be null or empty.</param>
/// <returns>
/// <c>true</c> if the IEnumerable is null or empty; otherwise, <c>false</c>.
/// </returns>
public static bool IsNullOrEmpty<T>(this IEnumerable<T> source)
{
if (source == null)
return true;
var sourceAsCollection = source as ICollection<T>;
if (sourceAsCollection != null)
return sourceAsCollection.Count < 1;
return sourceAsCollection.Any();
}
/// <summary>
/// Determines whether the collection is null or contains no elements.
/// </summary>
/// <typeparam name="T">The IEnumerable type.</typeparam>
/// <param name="source">The collection, which may be null or empty.</param>
/// <returns>
/// <c>true</c> if the IEnumerable is null or empty; otherwise, <c>false</c>.
/// </returns>
public static bool IsNullOrEmpty<T>(this ICollection<T> source)
{
if (source == null)
return true;
return source.Count < 1;
}
}
}
|