-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
68 lines (61 loc) · 1.85 KB
/
Utils.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace KeyBinder
{
class Utils
{
/// <summary>
/// Gets all values of given enum
/// </summary>
/// <typeparam name="T">Enum whose values we want</typeparam>
/// <returns>Values of the enum</returns>
public static IEnumerable<T> GetEnumValues<T>()
{
return Enum.GetValues(typeof(T)).Cast<T>();
}
public static bool CompareLists<T>(IEnumerable<T> list1, IEnumerable<T> list2)
{
var cnt = new Dictionary<T, int>();
foreach (T s in list1)
{
if (cnt.ContainsKey(s))
{
cnt[s]++;
}
else
{
cnt.Add(s, 1);
}
}
foreach (T s in list2)
{
if (cnt.ContainsKey(s))
{
cnt[s]--;
}
else
{
return false;
}
}
return cnt.Values.All(c => c == 0);
}
public static string converKeysToHotkeyString(HashSet<Key> keys)
{
return String.Join(" + ", keys.OrderBy(x => x));
}
public static bool isHotkeyDuplicatted(ViewModel viewModel)
{
HashSet<String> hotkeys = new HashSet<string>(viewModel.DataGridItems.Select(item => item.hotkey));
return viewModel.DataGridItems.Count() > hotkeys.Count;
}
public static bool isHotkeyDuplicatted(string hotkey, ViewModel viewModel)
{
return viewModel.DataGridItems.Where(entry => entry.hotkey.Equals(hotkey)).Count() > 0;
}
}
}