Skip to content
Tareq Imbasher edited this page May 15, 2025 · 1 revision

NetPad provides a handy static Util class to enhance your scripting experience with built-in helpers for dumping data, caching, environment access, and more.

Properties

Access runtime and script metadata:

Util.Script.Dump();
Util.Environment.Dump();
Util.Stopwatch.Elapsed.Dump();

Caching

Store and retrieve values with Util.Cache. Useful for expensive computations or repeated lookups:

var albums = Util.Cache.GetOrAdd("albums", () => Albums.ToArray());

Tip

Explore other Util.Cache methods via IntelliSense—they're well-documented and easy to use.

Open Files, Folders, and URLs

Launch external resources from your script:

Util.OpenFile("/path/img.png");
Util.OpenDirectory("/path/dir");
Util.OpenUrl("https://github.com");

Dumping Output

Dump an object, or value, for debugging and visualization:

Util.Dump<T>(
    T? o, 
    string? title = null, 
    string? css = null, 
    string? code = null, 
    int? clear = null);
    
Util.Dump<T>(T? o, DumpOptions options);

Dump formatted code snippets:

Util.DumpCode("<h1>Hello</h1>");

Render raw HTML:

Util.RawHtml("<h1>Heading 1</h1>");
Util.RawHtml(XElement.Parse("<h1>Heading 1</h1>"));

Host Lifecycle

Control how the script host behaves:

Util.RestartHostOnEveryRun = true; // Disables persisting state across runs. Default: false
Util.Terminate();                  // Terminates the running script and host process
Clone this wiki locally