Skip to content

Commit 83575cc

Browse files
committed
Sorted code.
1 parent 6b4de61 commit 83575cc

File tree

1 file changed

+90
-74
lines changed

1 file changed

+90
-74
lines changed

Util/Extensions.cs

Lines changed: 90 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,67 @@ namespace ReClassNET.Util
1111
public static class Extensions
1212
{
1313
[Pure]
14-
public static bool IsNearlyEqual(this float val, float other)
14+
public static int ToRgb(this Color color)
1515
{
16-
return IsNearlyEqual(val, other, float.Epsilon);
16+
return 0xFFFFFF & color.ToArgb();
1717
}
1818

1919
[Pure]
20-
public static bool IsNearlyEqual(this float val, float other, float epsilon)
20+
public static void FillWithZero(this byte[] b)
2121
{
22-
var diff = Math.Abs(val - other);
22+
Contract.Requires(b != null);
2323

24-
if (val == other)
25-
{
26-
return true;
27-
}
28-
else if (val == 0 || other == 0 || diff < float.Epsilon)
29-
{
30-
return diff < epsilon;
31-
}
32-
else
24+
for (var i = 0; i < b.Length; ++i)
3325
{
34-
return diff / (Math.Abs(val) + Math.Abs(other)) < epsilon;
26+
b[i] = 0;
3527
}
3628
}
3729

38-
[Pure]
39-
public static bool IsNearlyEqual(this double val, double other)
30+
public static void ShowDialog(this Exception ex)
4031
{
41-
return IsNearlyEqual(val, other, double.Epsilon);
32+
Contract.Requires(ex != null);
33+
34+
// This doesn't look good...
35+
ex.HelpLink = "https://github.com/KN4CK3R/ReClass.NET/issues";
36+
37+
var msg = new ExceptionMessageBox(ex);
38+
msg.ShowToolBar = true;
39+
msg.Symbol = ExceptionMessageBoxSymbol.Error;
40+
msg.Show(null);
4241
}
4342

4443
[Pure]
45-
public static bool IsNearlyEqual(this double val, double other, double epsilon)
44+
public static Point OffsetEx(this Point p, int x, int y)
4645
{
47-
var diff = Math.Abs(val - other);
46+
var temp = p;
47+
temp.Offset(x, y);
48+
return temp;
49+
}
4850

49-
if (val == other)
50-
{
51-
return true;
52-
}
53-
else if (val == 0 || other == 0 || diff < double.Epsilon)
54-
{
55-
return diff < epsilon;
56-
}
57-
else
51+
public static IEnumerable<BaseNode> Descendants(this BaseNode root)
52+
{
53+
Contract.Requires(root != null);
54+
55+
var nodes = new Stack<BaseNode>();
56+
nodes.Push(root);
57+
while (nodes.Any())
5858
{
59-
return diff / (Math.Abs(val) + Math.Abs(other)) < epsilon;
59+
var node = nodes.Pop();
60+
yield return node;
61+
62+
var classNode = node as ClassNode;
63+
if (classNode != null)
64+
{
65+
foreach (var child in classNode.Nodes)
66+
{
67+
nodes.Push(child);
68+
}
69+
}
6070
}
6171
}
6272

73+
#region Pointer
74+
6375
[Pure]
6476
public static bool IsNull(this IntPtr ptr)
6577
{
@@ -130,11 +142,9 @@ public static bool InRange(this IntPtr address, IntPtr start, IntPtr end)
130142
#endif
131143
}
132144

133-
[Pure]
134-
public static int ToRgb(this Color color)
135-
{
136-
return 0xFFFFFF & color.ToArgb();
137-
}
145+
#endregion
146+
147+
#region String
138148

139149
[Pure]
140150
public static bool IsPrintable(this char c)
@@ -194,14 +204,6 @@ public static float IsLikelyPrintableData(this IEnumerable<char> source)
194204
return countValid / (float)countAll;
195205
}
196206

197-
[Pure]
198-
public static Point OffsetEx(this Point p, int x, int y)
199-
{
200-
var temp = p;
201-
temp.Offset(x, y);
202-
return temp;
203-
}
204-
205207
[Pure]
206208
public static string LimitLength(this string s, int length)
207209
{
@@ -214,39 +216,64 @@ public static string LimitLength(this string s, int length)
214216
return s.Substring(0, length);
215217
}
216218

219+
#endregion
220+
221+
#region Floating Point
222+
217223
[Pure]
218-
public static void FillWithZero(this byte[] b)
224+
public static bool IsNearlyEqual(this float val, float other)
219225
{
220-
Contract.Requires(b != null);
226+
return IsNearlyEqual(val, other, float.Epsilon);
227+
}
221228

222-
for (var i = 0; i < b.Length; ++i)
229+
[Pure]
230+
public static bool IsNearlyEqual(this float val, float other, float epsilon)
231+
{
232+
var diff = Math.Abs(val - other);
233+
234+
if (val == other)
223235
{
224-
b[i] = 0;
236+
return true;
237+
}
238+
else if (val == 0 || other == 0 || diff < float.Epsilon)
239+
{
240+
return diff < epsilon;
241+
}
242+
else
243+
{
244+
return diff / (Math.Abs(val) + Math.Abs(other)) < epsilon;
225245
}
226246
}
227247

228-
public static IEnumerable<BaseNode> Descendants(this BaseNode root)
248+
[Pure]
249+
public static bool IsNearlyEqual(this double val, double other)
229250
{
230-
Contract.Requires(root != null);
251+
return IsNearlyEqual(val, other, double.Epsilon);
252+
}
231253

232-
var nodes = new Stack<BaseNode>();
233-
nodes.Push(root);
234-
while (nodes.Any())
235-
{
236-
var node = nodes.Pop();
237-
yield return node;
254+
[Pure]
255+
public static bool IsNearlyEqual(this double val, double other, double epsilon)
256+
{
257+
var diff = Math.Abs(val - other);
238258

239-
var classNode = node as ClassNode;
240-
if (classNode != null)
241-
{
242-
foreach (var child in classNode.Nodes)
243-
{
244-
nodes.Push(child);
245-
}
246-
}
259+
if (val == other)
260+
{
261+
return true;
262+
}
263+
else if (val == 0 || other == 0 || diff < double.Epsilon)
264+
{
265+
return diff < epsilon;
266+
}
267+
else
268+
{
269+
return diff / (Math.Abs(val) + Math.Abs(other)) < epsilon;
247270
}
248271
}
249272

273+
#endregion
274+
275+
#region Linq
276+
250277
public static int FindIndex<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
251278
{
252279
Contract.Requires(source != null);
@@ -336,17 +363,6 @@ public static IEnumerable<TSource> TakeUntil<TSource>(this IEnumerable<TSource>
336363
}
337364
}
338365

339-
public static void ShowDialog(this Exception ex)
340-
{
341-
Contract.Requires(ex != null);
342-
343-
// This doesn't look good...
344-
ex.HelpLink = "https://github.com/KN4CK3R/ReClass.NET/issues";
345-
346-
var msg = new ExceptionMessageBox(ex);
347-
msg.ShowToolBar = true;
348-
msg.Symbol = ExceptionMessageBoxSymbol.Error;
349-
msg.Show(null);
350-
}
366+
#endregion
351367
}
352368
}

0 commit comments

Comments
 (0)