Skip to content

🍦 Never use Console.WriteLine() to debug in .NET again.

License

Notifications You must be signed in to change notification settings

danielathome19/IceCream-Sharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IceCream# — Never use Console.WriteLine() to debug in .NET again.

NuGet CI/CT/CD License

IceCream# is a C# port of the icecream library for Python.

Do you ever use Console.WriteLine() or Debug.WriteLine() to debug your code? Of course you do. IceCream, or ic for short, makes print debugging a little sweeter.

ic() is like Console.WriteLine(), but better:

  • It prints both expressions/variable names and their values.
  • It's 60% faster to type.
  • Data structures are pretty printed.
  • Output is syntax highlighted.
  • It optionally includes program context: filename, parent class, parent function, and line number.
using static IceCream.IceCream;

ic("Hello, World!");
>>> ic| Program > <Main>$:3 > param_0 = Hello, World!

Installation

Install the IceCream-Sharp NuGet package:

dotnet add package IceCream-Sharp

Usage

using static IceCream.IceCream;

ic("Hello, World!");

Documentation

ic(params object[] objects)

ic() is the main function of IceCream#.

ic("Hello, World!");
>>> ic| Program > <Main>$:3 > param_0 = Hello, World!

All other functions are prefixed with IC_ to prevent name collisions from static importing.

IC_Format(params object[] objects)

IC_Format() formats the given objects for debugging, returning the formatted string.

using static IceCream.IceCream;
string formatted = IC_Format("Hello, World!");
Console.WriteLine(formatted);
>>> ic| Program > <Main>$:2 > param_0 = Hello, World!

IC_SetPrefix(string value)

IC_SetPrefix() sets a custom string prefix for the debugging output (default: ic| ).

using static IceCream.IceCream;
IC_SetPrefix("DEBUG: ");
ic("Hello, World!");
DEBUG: Program > <Main>$:3 > param_0 = Hello, World!

IC_SetPrefix(Func<string> func)

IC_SetPrefix() sets a custom function that returns a string prefix for the debugging output.

using static IceCream.IceCream;
IC_SetPrefix(() => $"[{DateTime.Now}] ");
ic("Hello, World!");
IC_SetPrefix(() => $"{DateTimeOffset.Now.ToUnixTimeSeconds()} |> ");
ic("Hello, World!");
[10/22/2023 12:00:00 AM] Program > <Main>$:3 > param_0 = Hello, World!
1634870400 |> Program > <Main>$:5 > param_0 = Hello, World!

IC_IncludeContext(bool incContext)

IC_IncludeContext() configures whether to include contextual information (like filename, classname, etc.) in the debugging output (default: true).

using static IceCream.IceCream;
IC_IncludeContext(false);
ic("Hello, World!");
>>> ic| param_0 = Hello, World!

IC_Enable() and IC_Disable()

IC_Enable() and IC_Disable() enable and disable the ic() function, respectively. When disabled, ic() will not print to the console.

using static IceCream.IceCream;
ic(1)
IC_Disable()
ic(2)
IC_Enable()
ic(3)
>>> ic| Program > <Main>$:2 > param_0 = 1
>>> ic| Program > <Main>$:6 > param_0 = 3

IC_IncludeFilename(bool flag)

IC_IncludeFilename() configures whether to include the filename in the debugging output (default: false).

using static IceCream.IceCream;
IC_IncludeFilename(true);
ic("Hello, World!");
>>> ic| Program.cs > Program > <Main>$:3 > param_0 = Hello, World!

IC_IncludeClassName(bool flag)

IC_IncludeClassName() configures whether to include the class name in the debugging output (default: true).

using static IceCream.IceCream;
IC_IncludeClassName(false);
ic("Hello, World!");
>>> ic| <Main>$:3 > param_0 = Hello, World!

IC_IncludeAbsolutePath(bool flag)

IC_IncludeAbsolutePath() configures whether to include the absolute path of the file in the debugging output (default: false).

using static IceCream.IceCream;
IC_IncludeAbsolutePath(true);
ic("Hello, World!");
>>> ic| C:\\Absolute\\Path\\To\\Program.cs > Program > <Main>$:3 > param_0 = Hello, World!

IC_IncludeMethodName(bool flag)

IC_IncludeMethodName() configures whether to include the method name in the debugging output (default: true).

using static IceCream.IceCream;
IC_IncludeMethodName(false);
ic("Hello, World!");
>>> ic| Program > 3: param_0 = Hello, World!

IC_IncludeLineNumber(bool flag)

IC_IncludeLineNumber() configures whether to include the line number in the debugging output (default: true).

using static IceCream.IceCream;
IC_IncludeLineNumber(false);
ic("Hello, World!");
>>> ic| Program > <Main>$: param_0 = Hello, World!

About

🍦 Never use Console.WriteLine() to debug in .NET again.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages