5
5
namespace Exceptionless {
6
6
internal static class CollectionEqualityExtensions {
7
7
public static bool CollectionEquals < T > ( this IEnumerable < T > source , IEnumerable < T > other ) {
8
+ if ( source == null && other == null )
9
+ return true ;
10
+
11
+ if ( source == null || other == null )
12
+ return false ;
13
+
8
14
var sourceEnumerator = source . GetEnumerator ( ) ;
9
15
var otherEnumerator = other . GetEnumerator ( ) ;
10
16
@@ -14,23 +20,29 @@ public static bool CollectionEquals<T>(this IEnumerable<T> source, IEnumerable<T
14
20
return false ;
15
21
}
16
22
17
- if ( sourceEnumerator . Current . Equals ( otherEnumerator . Current ) ) {
18
- // values aren't equal
23
+ var sourceValue = sourceEnumerator . Current ;
24
+ var otherValue = otherEnumerator . Current ;
25
+ if ( sourceValue == null && otherValue == null )
26
+ continue ;
27
+
28
+ if ( source == null || other == null || ! sourceValue . Equals ( otherValue ) )
19
29
return false ;
20
- }
21
30
}
22
31
23
32
if ( otherEnumerator . MoveNext ( ) ) {
24
33
// counts differ
25
34
return false ;
26
35
}
36
+
27
37
return true ;
28
38
}
29
39
30
40
public static bool CollectionEquals < TValue > ( this IDictionary < string , TValue > source , IDictionary < string , TValue > other ) {
31
- if ( source . Count != other . Count ) {
41
+ if ( source == null && other == null )
42
+ return true ;
43
+
44
+ if ( source == null || other == null || source . Count != other . Count )
32
45
return false ;
33
- }
34
46
35
47
foreach ( var key in source . Keys ) {
36
48
var sourceValue = source [ key ] ;
@@ -40,12 +52,26 @@ public static bool CollectionEquals<TValue>(this IDictionary<string, TValue> sou
40
52
return false ;
41
53
}
42
54
43
- if ( sourceValue . Equals ( otherValue ) ) {
55
+ if ( sourceValue == null && otherValue == null )
56
+ continue ;
57
+
58
+ if ( source == null || other == null || ! sourceValue . Equals ( otherValue ) )
44
59
return false ;
45
- }
46
60
}
61
+
47
62
return true ;
48
63
}
64
+
65
+
66
+ public static bool CollectionEquals < TValue > ( this ISet < TValue > source , ISet < TValue > other ) {
67
+ if ( source == null && other == null )
68
+ return true ;
69
+
70
+ if ( source == null || other == null || source . Count != other . Count )
71
+ return false ;
72
+
73
+ return source . SetEquals ( other ) ;
74
+ }
49
75
50
76
public static int GetCollectionHashCode < T > ( this IEnumerable < T > source ) {
51
77
var assemblyQualifiedName = typeof ( T ) . AssemblyQualifiedName ;
0 commit comments