Shartilities is a simple, evolving C# utilities library designed to handle common tasks like logging, command execution, file I/O, and argument parsing with minimal boilerplate.
When you add this library as a project reference to your solution, you do not need to include a using statement if the namespace is global or shared. You can simply access the static class directly.
Example Usage:
namespace ProjectName
{
internal class Program
{
static void Main(string[] args)
{
// Simple color-coded logging
Shartilities.Log(Shartilities.LogType.INFO, "Hello World\n");
// Argument handling
if (Shartilities.ShiftArgs(ref args, out string mode))
{
Console.WriteLine($"Mode selected: {mode}");
}
}
}
}Provides color-coded console output for different severity levels.
- Enum:
LogType.INFO(Green),LogType.WARNING(Yellow),LogType.ERROR(Red). - Methods:
Log(LogType, msg): Prints formatted message.Logln(LogType, msg): Prints formatted message with a new line.
A wrapper struct Command to simplify running external processes synchronously or asynchronously.
-
Features:
-
Run commands and capture
stdout/stderr. -
Support for real-time output streaming.
-
Async execution via
CliWrap. -
Usage:
var cmd = new Shartilities.Command(["git", "status"]);
if (cmd.RunSyncStatic(ref process, out string output, out string error))
{
Console.WriteLine(output);
}Helper methods for reading/writing files and serializing objects to XML.
- Text I/O:
ReadFile,WriteFile(handles directory creation automatically). - XML Serialization:
SaveObject<T>(path, obj): Serializes an object to XML.LoadObject<T>(path): Deserializes an XML file back to an object.
-
Argument Parsing:
ShiftArgsconsumes the first argument from an array (similar to shell scriptingshift). -
Control Flow:
-
UNREACHABLE(msg): Logs error and exits with code 1. -
TODO(msg): Logs error and exits with code 1. -
Assert(condition, msg): Exits if the condition is false. -
String Tools:
SplitAndRemoveWhitesplits strings by spaces and removes empty entries.
This library utilizes the following external packages:
- CliWrap (for command execution)
Open Source.