-
Notifications
You must be signed in to change notification settings - Fork 4
/
ComboBoxValueComparer.cs
46 lines (40 loc) · 1.65 KB
/
ComboBoxValueComparer.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
/*
* Program : JuisCheck for Windows
* Copyright : Copyright (C) Roger Hünen
* License : GNU General Public License version 3 (see LICENSE)
*/
using System;
using System.Collections.Generic;
namespace JuisCheck
{
public sealed class ComboBoxValueComparer : Comparer<ComboBoxValue>
{
private readonly IComparer<string> comparer;
public ComboBoxValueComparer( StringComparison stringComparison )
{
switch (stringComparison) {
case StringComparison.CurrentCulture: comparer = StringComparer.CurrentCulture; break;
case StringComparison.CurrentCultureIgnoreCase: comparer = StringComparer.CurrentCultureIgnoreCase; break;
case StringComparison.InvariantCulture: comparer = StringComparer.InvariantCulture; break;
case StringComparison.InvariantCultureIgnoreCase: comparer = StringComparer.InvariantCultureIgnoreCase; break;
case StringComparison.Ordinal: comparer = StringComparer.Ordinal; break;
case StringComparison.OrdinalIgnoreCase: comparer = StringComparer.OrdinalIgnoreCase; break;
default: throw new ArgumentOutOfRangeException(nameof(stringComparison));
}
}
public ComboBoxValueComparer( IComparer<string> stringComparer )
{
comparer = stringComparer ?? throw new ArgumentNullException(nameof(stringComparer));
}
public override int Compare( ComboBoxValue value1, ComboBoxValue value2 )
{
if (value1 == null) {
throw new ArgumentNullException(nameof(value1));
}
if (value2 == null) {
throw new ArgumentNullException(nameof(value2));
}
return comparer.Compare(value1.DisplayString, value2.DisplayString);
}
}
}