Skip to content

Commit

Permalink
Test for dynamically created culture info, rider refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ptr727 committed Mar 22, 2023
1 parent f694f2d commit d942f80
Show file tree
Hide file tree
Showing 17 changed files with 9,030 additions and 9,147 deletions.
53 changes: 26 additions & 27 deletions Utilities/CommandLineEx.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
using System;

namespace InsaneGenius.Utilities
namespace InsaneGenius.Utilities;

public static class CommandLineEx
{
public static class CommandLineEx
// https://stackoverflow.com/questions/298830/split-string-containing-command-line-parameters-into-string-in-c-sharp
public static string[] ParseArguments(string commandLine)
{
// https://stackoverflow.com/questions/298830/split-string-containing-command-line-parameters-into-string-in-c-sharp
public static string[] ParseArguments(string commandLine)
{
if (commandLine == null)
throw new ArgumentNullException(nameof(commandLine));
if (commandLine == null)
throw new ArgumentNullException(nameof(commandLine));

char[] paramChars = commandLine.ToCharArray();
bool inQuote = false;
for (int index = 0; index < paramChars.Length; index++)
{
if (paramChars[index] == '"')
inQuote = !inQuote;
if (!inQuote && paramChars[index] == ' ')
paramChars[index] = '\n';
}
return new string(paramChars).Split('\n');
char[] paramChars = commandLine.ToCharArray();
bool inQuote = false;
for (int index = 0; index < paramChars.Length; index++)
{
if (paramChars[index] == '"')
inQuote = !inQuote;
if (!inQuote && paramChars[index] == ' ')
paramChars[index] = '\n';
}
return new string(paramChars).Split('\n');
}

public static string[] GetCommandLineArgs()
{
// Split the arguments
string[] args = ParseArguments(Environment.CommandLine);
public static string[] GetCommandLineArgs()
{
// Split the arguments
string[] args = ParseArguments(Environment.CommandLine);

// Strip the process path from the list of arguments
string[] argsEx = new string[args.Length - 1];
Array.Copy(args, 1, argsEx, 0, argsEx.Length);
return argsEx;
}
// Strip the process path from the list of arguments
string[] argsEx = new string[args.Length - 1];
Array.Copy(args, 1, argsEx, 0, argsEx.Length);
return argsEx;
}
}
}
131 changes: 65 additions & 66 deletions Utilities/ConsoleEx.cs
Original file line number Diff line number Diff line change
@@ -1,84 +1,83 @@
using System;
using System.Globalization;

namespace InsaneGenius.Utilities
namespace InsaneGenius.Utilities;

public static class ConsoleEx
{
public static class ConsoleEx
public static void WriteLineColor(ConsoleColor color, string value)
{
public static void WriteLineColor(ConsoleColor color, string value)
// Locking only works when using this function
// Mixing any other console output may still result in mismatched color output
lock (WriteLineLock)
{
// Locking only works when using this function
// Mixing any other console output may still result in mismatched color output
lock (WriteLineLock)
{
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.WriteLine(string.IsNullOrEmpty(value) ? $"{value}" : $"{DateTime.Now.ToString(CultureInfo.CurrentCulture)} : {value}");
Console.ForegroundColor = oldColor;
}
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.WriteLine(string.IsNullOrEmpty(value) ? $"{value}" : $"{DateTime.Now.ToString(CultureInfo.CurrentCulture)} : {value}");
Console.ForegroundColor = oldColor;
}
public static void WriteLineColor(ConsoleColor color, object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
}
public static void WriteLineColor(ConsoleColor color, object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));

WriteLineColor(color, value.ToString());
}
WriteLineColor(color, value.ToString());
}

public static void WriteLineError(string value)
{
WriteLineColor(ErrorColor, value);
}
public static void WriteLineError(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
public static void WriteLineError(string value)
{
WriteLineColor(ErrorColor, value);
}
public static void WriteLineError(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));

WriteLineError(value.ToString());
}
WriteLineError(value.ToString());
}

public static void WriteLineEvent(string value)
{
WriteLineColor(EventColor, value);
}
public static void WriteLineEvent(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
public static void WriteLineEvent(string value)
{
WriteLineColor(EventColor, value);
}
public static void WriteLineEvent(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));

WriteLineEvent(value.ToString());
}
WriteLineEvent(value.ToString());
}

public static void WriteLineTool(string value)
{
WriteLineColor(ToolColor, value);
}
public static void WriteLineTool(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
public static void WriteLineTool(string value)
{
WriteLineColor(ToolColor, value);
}
public static void WriteLineTool(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));

WriteLineTool(value.ToString());
}
WriteLineTool(value.ToString());
}

public static void WriteLine(string value)
{
WriteLineColor(OutputColor, value);
}
public static void WriteLine(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
public static void WriteLine(string value)
{
WriteLineColor(OutputColor, value);
}
public static void WriteLine(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));

WriteLine(value.ToString());
}
WriteLine(value.ToString());
}

private static readonly object WriteLineLock = new object();
private static readonly object WriteLineLock = new();

// Good looking console colors; Green, Cyan, Red, Magenta, Yellow, White
public const ConsoleColor ToolColor = ConsoleColor.Green;
public const ConsoleColor ErrorColor = ConsoleColor.Red;
public const ConsoleColor OutputColor = ConsoleColor.Cyan;
public const ConsoleColor EventColor = ConsoleColor.Yellow;
}
}
// Good looking console colors; Green, Cyan, Red, Magenta, Yellow, White
public const ConsoleColor ToolColor = ConsoleColor.Green;
public const ConsoleColor ErrorColor = ConsoleColor.Red;
public const ConsoleColor OutputColor = ConsoleColor.Cyan;
public const ConsoleColor EventColor = ConsoleColor.Yellow;
}
Loading

0 comments on commit d942f80

Please sign in to comment.