Skip to content

Commit d5f138c

Browse files
Merge pull request #4 from MrUnbelievable92/v1.0.7
Update v1.0.7
2 parents 72a8a06 + aa4c45a commit d5f138c

File tree

7 files changed

+519
-207
lines changed

7 files changed

+519
-207
lines changed

AssemblyInfo.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("")]
1111
[assembly: AssemblyProduct("C Sharp Dev Tools")]
12-
[assembly: AssemblyCopyright("Copyright © 2020 - 2021 Maximilian Kalimon")]
12+
[assembly: AssemblyCopyright("Copyright 2020 - 2022 Maximilian Kalimon")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -28,6 +28,5 @@
2828
// Build Number
2929
// Revision
3030
//
31-
[assembly: AssemblyVersion("1.0.6")]
32-
[assembly: AssemblyFileVersion("1.0.6")]
33-
31+
[assembly: AssemblyVersion("1.0.7")]
32+
[assembly: AssemblyFileVersion("1.0.7")]

Assert.cs

Lines changed: 280 additions & 14 deletions
Large diffs are not rendered by default.

C Sharp Dev Tools.asmdef

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "CSharpDevTools",
3-
"rootNamespace": "",
3+
"rootNamespace": "DevTools",
44
"references": [],
55
"includePlatforms": [],
66
"excludePlatforms": [],

Dump.cs

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
1-
namespace DevTools
1+
namespace DevTools
22
{
33
unsafe public static class Dump
44
{
55
public static string Bits(byte value, bool spaces = true)
66
{
7-
if (spaces)
8-
{
9-
char* result = stackalloc char[9];
10-
11-
for (int i = 0; i < 4; i++)
12-
{
13-
result[i] = (char)(((value >> (7 - i)) & 1) + '0');
14-
}
15-
16-
result[4] = ' ';
17-
18-
for (int i = 5; i < 9; i++)
19-
{
20-
result[i] = (char)(((value >> (7 - i)) & 1) + '0');
21-
}
7+
char* result = stackalloc char[8];
228

23-
return new string(result, 0, 9);
24-
}
25-
else
9+
for (int i = 0; i < 8; i++)
2610
{
27-
char* result = stackalloc char[8];
28-
29-
for (int i = 0; i < 8; i++)
30-
{
31-
result[i] = (char)(((value >> (7 - i)) & 1) + '0');
32-
}
33-
34-
return new string(result, 0, 8);
11+
result[i] = (char)(((value >> (7 - i)) & 1) + '0');
3512
}
13+
14+
return new string(result, 0, 8).Insert(4, spaces ? " " : "");
3615
}
3716

3817
public static string Bits<T>(T value, bool spaces = true)
@@ -51,7 +30,7 @@ public static string Bits(void* ptr, int bytes, bool spaces = true)
5130

5231
while (bytes != 0)
5332
{
54-
result = result.Insert(0, Bits(*address, spaces) + (spaces ? " " : string.Empty));
33+
result = result.Insert(0, Bits(*address, spaces) + (spaces ? " " : ""));
5534

5635
address++;
5736
bytes--;
@@ -61,15 +40,20 @@ public static string Bits(void* ptr, int bytes, bool spaces = true)
6140
}
6241

6342

64-
public static string Hex(byte value)
43+
private static string Hex(byte value, char* HEX_VALUES)
6544
{
66-
char* HEX_VALUES = stackalloc char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
67-
6845
char* result = stackalloc char[] { HEX_VALUES[value >> 4], HEX_VALUES[value & 0b1111] };
6946

7047
return new string(result, 0, 2);
7148
}
7249

50+
public static string Hex(byte value)
51+
{
52+
char* HEX_VALUES = stackalloc char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
53+
54+
return Hex(value, HEX_VALUES);
55+
}
56+
7357
public static string Hex<T>(T value, bool spaces = true)
7458
where T : unmanaged
7559
{
@@ -80,20 +64,27 @@ public static string Hex(void* ptr, int bytes, bool spaces = true)
8064
{
8165
Assert.IsNotNull(ptr);
8266
Assert.IsNonNegative(bytes);
67+
68+
char* HEX_VALUES = stackalloc char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
8369

8470
byte* address = (byte*)ptr;
85-
int iterations = 0;
71+
uint iterations = 0;
8672
string result = string.Empty;
8773

8874
while (iterations != bytes)
8975
{
90-
result = result.Insert(0, Hex(*address) + ((spaces && (iterations != 0) && (iterations % 2 == 0)) ? " " : string.Empty));
91-
76+
string block = Hex(*address, HEX_VALUES);
77+
if (spaces && (iterations != 0) & (iterations % 2 == 0))
78+
{
79+
block += " ";
80+
}
81+
result = result.Insert(0, block);
82+
9283
address++;
9384
iterations++;
9485
}
9586

9687
return result;
9788
}
9889
}
99-
}
90+
}

Extensions/DirectoryExtensions.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.IO;
2+
3+
namespace DevTools
4+
{
5+
public static class DirectoryExtensions
6+
{
7+
/// <summary> Appends <see cref="Path.DirectorySeparatorChar"/> to '<paramref name="directory"/>' and returns the result. </summary>
8+
public static string AsDirectory(this string directory)
9+
{
10+
return directory + Path.DirectorySeparatorChar;
11+
}
12+
13+
/// <summary> Recursively searches for a file '<paramref name="fileName"/>' in the '<paramref name="folder"/>' directory, including subdirectories. </summary>
14+
public static string FindInFolder(string folder, string fileName)
15+
{
16+
string result = folder.AsDirectory() + fileName;
17+
if (File.Exists(result))
18+
{
19+
return result;
20+
}
21+
22+
foreach (string subDirectory in Directory.GetDirectories(folder))
23+
{
24+
result = FindInFolder(subDirectory, fileName);
25+
if (result != null)
26+
{
27+
return result;
28+
}
29+
}
30+
31+
return null;
32+
}
33+
34+
/// <summary> Deletes a directory '<paramref name="folder"/>' and all of its contents, including subdirectories. </summary>
35+
public static void DeleteFolder(string folder)
36+
{
37+
foreach (string subFolder in Directory.GetDirectories(folder))
38+
{
39+
DeleteFolder(subFolder);
40+
}
41+
42+
foreach (string file in Directory.GetFiles(folder))
43+
{
44+
File.Delete(file);
45+
}
46+
47+
Directory.Delete(folder);
48+
}
49+
}
50+
}

Extensions/GenericExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace DevTools
4+
{
5+
public static class GenericExtensions
6+
{
7+
/// <summary> Logs a message of type '<typeparamref name="T"/>' to the console. </summary>
8+
public static void Log<T>(this T obj)
9+
{
10+
#if DEBUG
11+
#if UNITY_EDITOR
12+
UnityEngine.Debug.Log(obj);
13+
#else
14+
Console.WriteLine(obj);
15+
#endif
16+
#endif
17+
}
18+
19+
/// <summary> Logs a message of type '<typeparamref name="T"/>' to the console. </summary>
20+
public static void Log<T>(this T obj, string format, IFormatProvider formatProvider = null)
21+
where T : IFormattable
22+
{
23+
Log(obj.ToString(format, formatProvider));
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)