@@ -18,6 +18,18 @@ public static void Add<T>(this ICollection<T> collection, IEnumerable<T> items)
1818 collection . Add ( item ) ;
1919 }
2020
21+ public static ReadOnlyCollection < T > AsReadOnly < T > ( this ICollection < T > collection )
22+ {
23+ Assert . IsNotNull ( collection , nameof ( collection ) ) ;
24+ return new ReadOnlyCollection < T > ( collection . ToList ( ) ) ;
25+ }
26+
27+ public static ICollection < TResult > Cast < TResult > ( this ICollection source )
28+ {
29+ ICollection < TResult > collection = source != null ? new CastedCollection < TResult > ( source ) : null ;
30+ return collection ;
31+ }
32+
2133 public static bool IsNullOrEmpty ( this ICollection collection )
2234 {
2335 var isNullOrEmpty = collection == null || collection . Count == 0 ;
@@ -30,6 +42,8 @@ public static bool IsNullOrEmpty<T>(this ICollection<T> collection)
3042 return isNullOrEmpty ;
3143 }
3244
45+ public static bool IsNullOrAny < T > ( this ICollection < T > source ) => source != null && source . Count > 0 ;
46+
3347 public static int Remove < T > ( this ICollection < T > collection , IEnumerable < T > items )
3448 {
3549 Assert . IsTrue ( collection != null || items == null ) ;
@@ -47,20 +61,6 @@ public static int Remove<T>(this ICollection<T> collection, IEnumerable<T> items
4761 return count ;
4862 }
4963
50- public static ReadOnlyCollection < T > AsReadOnly < T > ( this ICollection < T > collection )
51- {
52- Assert . IsNotNull ( collection , nameof ( collection ) ) ;
53- return new ReadOnlyCollection < T > ( collection . ToList ( ) ) ;
54- }
55-
56- public static ICollection < TResult > Cast < TResult > ( this ICollection source )
57- {
58- ICollection < TResult > collection = source != null ? new CastedCollection < TResult > ( source ) : null ;
59- return collection ;
60- }
61-
62- public static bool IsNullOrAny < T > ( this ICollection < T > source ) => source != null && source . Count > 0 ;
63-
6464 public static T [ ] ToArray < T > ( ICollection < T > source )
6565 {
6666 Assert . IsNotNull ( source , nameof ( source ) ) ;
0 commit comments