forked from ReClassNET/ReClass.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensions.cs
More file actions
95 lines (82 loc) · 1.61 KB
/
Copy pathExtensions.cs
File metadata and controls
95 lines (82 loc) · 1.61 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Linq;
using ReClassNET.Nodes;
namespace ReClassNET.Extensions
{
public static class Extensions
{
[Pure]
[DebuggerStepThrough]
public static int ToRgb(this Color color)
{
return 0xFFFFFF & color.ToArgb();
}
[DebuggerStepThrough]
public static void FillWithZero(this byte[] b)
{
Contract.Requires(b != null);
for (var i = 0; i < b.Length; ++i)
{
b[i] = 0;
}
}
[Pure]
[DebuggerStepThrough]
public static Point OffsetEx(this Point p, int x, int y)
{
var temp = p;
temp.Offset(x, y);
return temp;
}
public static IEnumerable<BaseNode> Descendants(this BaseNode root)
{
Contract.Requires(root != null);
var nodes = new Stack<BaseNode>();
nodes.Push(root);
while (nodes.Any())
{
var node = nodes.Pop();
yield return node;
if (node is ClassNode classNode)
{
foreach (var child in classNode.Nodes)
{
nodes.Push(child);
}
}
}
}
#region List
[DebuggerStepThrough]
public static T BinaryFind<T>(this IList<T> source, Func<T, int> comparer)
{
Contract.Requires(source != null);
Contract.Requires(comparer != null);
var lo = 0;
var hi = source.Count - 1;
while (lo <= hi)
{
var median = lo + (hi - lo >> 1);
var num = comparer(source[median]);
if (num == 0)
{
return source[median];
}
if (num > 0)
{
lo = median + 1;
}
else
{
hi = median - 1;
}
}
return default(T);
}
#endregion
}
}