Skip to content

Nedal-haltam/Shartilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shartilities

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.

Getting Started

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}");
            }
        }
    }
}

Features

1. Logging

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.

2. Command Execution

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);
}

3. File I/O & Serialization

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.

4. Utilities & Debugging

  • Argument Parsing: ShiftArgs consumes the first argument from an array (similar to shell scripting shift).

  • 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: SplitAndRemoveWhite splits strings by spaces and removes empty entries.

Dependencies

This library utilizes the following external packages:

License

Open Source.

About

A C# utilities class library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages