forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByteArrayExtensions.cs
More file actions
44 lines (38 loc) · 1.08 KB
/
ByteArrayExtensions.cs
File metadata and controls
44 lines (38 loc) · 1.08 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace ServiceStack
{
public static class ByteArrayExtensions
{
public static bool AreEqual(this byte[] b1, byte[] b2)
{
if (b1 == b2) return true;
if (b1 == null || b2 == null) return false;
if (b1.Length != b2.Length) return false;
for (var i = 0; i < b1.Length; i++)
{
if (b1[i] != b2[i]) return false;
}
return true;
}
}
public class ByteArrayComparer : IEqualityComparer<byte[]>
{
public static ByteArrayComparer Instance = new ByteArrayComparer();
public bool Equals(byte[] left, byte[] right)
{
if (left == null || right == null)
{
return left == right;
}
return left.SequenceEqual(right);
}
public int GetHashCode(byte[] key)
{
if (key == null)
throw new ArgumentNullException("key");
return key.Sum(b => b);
}
}
}