-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGlobal.cs
37 lines (33 loc) · 1.28 KB
/
Global.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Save_Editor {
public static class Global {
public static string ToHexString(byte[] bytes) {
var hex = new StringBuilder(bytes.Length * 2);
foreach (var b in bytes) {
hex.AppendFormat("{0:x2}", b);
}
return hex.ToString();
}
public static byte[] StringToByteArray(string hex) {
var numberChars = hex.Length;
var bytes = new byte[numberChars / 2];
for (var i = 0; i < numberChars; i += 2) {
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
public static string FromHexStringToGuidString(this string hexString) {
return new Guid(StringToByteArray(hexString.Replace(" ", "").Replace("-", ""))).ToString();
}
public static void CopyTo<K, V>(this IEnumerable<KeyValuePair<K, V>> source, Dictionary<K, V> dest, bool ignoreDuplicates = false) {
source.ToList()
.ForEach(x => {
if (ignoreDuplicates && dest.ContainsKey(x.Key)) return;
dest.Add(x.Key, x.Value);
});
}
}
}