wasSharp – Blame information for rev 52
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
39 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System; |
||
52 | office | 8 | using System.Text; |
39 | office | 9 | using System.Threading.Tasks; |
10 | |||
11 | namespace wasSharp |
||
12 | { |
||
13 | public static class Extensions |
||
14 | { |
||
15 | /// <summary> |
||
16 | /// Combine two UUIDs together by taking the MD5 hash of a byte array |
||
17 | /// containing both UUIDs |
||
18 | /// </summary> |
||
19 | /// <param name="first">First UUID to combine</param> |
||
20 | /// <param name="second">Second UUID to combine</param> |
||
21 | /// <returns>The UUID product of the combination</returns> |
||
22 | public static Guid CombineXOR(this Guid p, Guid q) |
||
23 | { |
||
24 | var l = p.ToByteArray(); |
||
25 | var r = q.ToByteArray(); |
||
26 | byte[] combine = new byte[16]; |
||
27 | Parallel.For(0, 16, i => |
||
28 | { |
||
29 | combine[i] = (byte)(l[i] ^ r[i]); |
||
30 | }); |
||
31 | |||
32 | return new Guid(combine); |
||
33 | } |
||
52 | office | 34 | |
35 | /// <summary> |
||
36 | /// Converts a byte array to a hexadecimal string. |
||
37 | /// </summary> |
||
38 | /// <param name="bytes"></param> |
||
39 | /// <returns></returns> |
||
40 | public static string ToHexString(this byte[] bytes) |
||
41 | { |
||
42 | StringBuilder str = new StringBuilder(); |
||
43 | |||
44 | for (int i = 0; i < bytes.Length; i++) |
||
45 | str.AppendFormat("{0:X2}", bytes[i]); |
||
46 | |||
47 | return str.ToString(); |
||
48 | } |
||
39 | office | 49 | } |
50 | } |