Skip to content

Commit 15a1b25

Browse files
committed
Optimizing code
- Changed project type to winexe to avoid showing console window when using the app. - Moved help text to help method.
1 parent a063785 commit 15a1b25

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

GUIDGen/GUIDGen.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<ProjectGuid>{510849CE-B423-4AF4-84F9-0B93900FB25B}</ProjectGuid>
8-
<OutputType>Exe</OutputType>
8+
<OutputType>WinExe</OutputType>
99
<RootNamespace>GUIDGen</RootNamespace>
1010
<AssemblyName>GUIDGen</AssemblyName>
1111
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>

GUIDGen/Program.cs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
internal static class Program {
66

7+
#region internal static int Main(...)
78
[STAThread]
89
internal static int Main(string[] args) {
910

@@ -12,34 +13,15 @@ internal static int Main(string[] args) {
1213
try {
1314
mode = Convert.ToInt32(args[0].ToLower().Replace("mode=", ""));
1415
} catch {
15-
Console.WriteLine("Creates a new GUID and copies it to clipboard");
16-
Console.WriteLine("Usage:");
17-
Console.WriteLine(" GuidGen [mode=1~6]");
18-
Console.WriteLine();
19-
Console.WriteLine(" mode is optional number between 1 to 6 to create guid in different formats as following");
20-
Console.WriteLine(" 1: String");
21-
Console.WriteLine(" Example: {CFB78D94-052F-46F5-87C3-0133A7B280BA}");
22-
Console.WriteLine();
23-
Console.WriteLine(" 2: Array of 16 hex bytes");
24-
Console.WriteLine(" Example: new byte[] { 0x94, 0x8D, 0xB7, 0xCF, 0x2F, 0x05, 0xF5, 0x46, 0x87, 0xC3, 0x01, 0x33, 0xA7, 0xB2, 0x80, 0xBA }");
25-
Console.WriteLine();
26-
Console.WriteLine(" 3: 16 bytes array is base 10 numbers");
27-
Console.WriteLine(" Example: new byte[] { 148, 141, 183, 207, 47, 5, 245, 70, 135, 195, 1, 51, 167, 178, 128, 186 }");
28-
Console.WriteLine();
29-
Console.WriteLine(" 4: int, short , short, byte[8]");
30-
Console.WriteLine(" Example: -810054252, 1327, 18165, new byte[] { 135, 195, 1, 51, 167, 178, 128, 186 }");
31-
Console.WriteLine();
32-
Console.WriteLine(" 5: int, short, short, byte, byte, byte, byte, byte, byte, byte, byte");
33-
Console.WriteLine(" Example: -810054252, 1327, 18165, 135, 195, 1, 51, 167, 178, 128, 186");
34-
Console.WriteLine();
35-
Console.WriteLine(" 6: uint, ushort, ushort, byte, byte, byte, byte, byte, byte, byte, byte");
36-
Console.WriteLine(" Example: 0xCFB78D94, 0x052F, 0x46F5, 0x87, 0xC3, 0x01, 0x33, 0xA7, 0xB2, 0x80, 0xBA");
16+
Help();
3717
}
3818
}
3919
Clipboard.SetText(GenerateGuidText(Guid.NewGuid(), mode));
4020
return 0;
4121
}
22+
#endregion
4223

24+
#region internal static string GenerateGuidText(...)
4325
internal static string GenerateGuidText(Guid guid, int mode) {
4426
StringBuilder sb = new StringBuilder();
4527
byte[] bytearr = guid.ToByteArray();
@@ -117,4 +99,33 @@ internal static string GenerateGuidText(Guid guid, int mode) {
11799

118100
return sb.ToString().Replace(", }", "}").TrimEnd(' ', ',');
119101
}
102+
#endregion
103+
104+
#region private static void Help()
105+
private static void Help() {
106+
Console.WriteLine("Creates a new GUID and copies it to clipboard");
107+
Console.WriteLine("Usage:");
108+
Console.WriteLine(" GuidGen [mode=1~6]");
109+
Console.WriteLine();
110+
Console.WriteLine(" mode is optional number between 1 to 6 to create guid in different formats as following");
111+
Console.WriteLine(" 1: String");
112+
Console.WriteLine(" Example: CFB78D94-052F-46F5-87C3-0133A7B280BA");
113+
Console.WriteLine();
114+
Console.WriteLine(" 2: Array of 16 hex bytes");
115+
Console.WriteLine(" Example: new byte[] { 0x94, 0x8D, 0xB7, 0xCF, 0x2F, 0x05, 0xF5, 0x46, 0x87, 0xC3, 0x01, 0x33, 0xA7, 0xB2, 0x80, 0xBA }");
116+
Console.WriteLine();
117+
Console.WriteLine(" 3: 16 bytes array is base 10 numbers");
118+
Console.WriteLine(" Example: new byte[] { 148, 141, 183, 207, 47, 5, 245, 70, 135, 195, 1, 51, 167, 178, 128, 186 }");
119+
Console.WriteLine();
120+
Console.WriteLine(" 4: int, short , short, byte[8]");
121+
Console.WriteLine(" Example: -810054252, 1327, 18165, new byte[] { 135, 195, 1, 51, 167, 178, 128, 186 }");
122+
Console.WriteLine();
123+
Console.WriteLine(" 5: int, short, short, byte, byte, byte, byte, byte, byte, byte, byte");
124+
Console.WriteLine(" Example: -810054252, 1327, 18165, 135, 195, 1, 51, 167, 178, 128, 186");
125+
Console.WriteLine();
126+
Console.WriteLine(" 6: uint, ushort, ushort, byte, byte, byte, byte, byte, byte, byte, byte");
127+
Console.WriteLine(" Example: 0xCFB78D94, 0x052F, 0x46F5, 0x87, 0xC3, 0x01, 0x33, 0xA7, 0xB2, 0x80, 0xBA");
128+
}
129+
#endregion
130+
120131
}

0 commit comments

Comments
 (0)