forked from geloczi/synologydotnet-audiostation-wpf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringMultiComparer.cs
47 lines (44 loc) · 1.25 KB
/
StringMultiComparer.cs
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
using System;
namespace Utils
{
public class StringMultiComparer
{
private readonly StringComparison[] _comparions;
public StringMultiComparer(params StringComparison[] comparisons)
{
if (!(comparisons?.Length > 0))
throw new ArgumentException(nameof(comparisons));
_comparions = comparisons;
}
public bool Equals(string s1, string s2)
{
if (s1 is null ^ s2 is null)
return false;
if (s1 is null)
return true;
foreach (var c in _comparions)
{
if (string.Compare(s1, s2, c) == 0)
return true;
}
return false;
}
public bool Equals(string[] s1, string[] s2)
{
if (s1 is null ^ s2 is null)
return false;
if (s1 is null)
return true;
if (s1.Length != s2.Length)
return false;
if (s1.Length == 0)
return true;
for (int i = 0; i < s1.Length; i++)
{
if (!Equals(s1[i], s2[i]))
return false;
}
return true;
}
}
}