forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptEnvironment.cs
More file actions
38 lines (31 loc) · 994 Bytes
/
ScriptEnvironment.cs
File metadata and controls
38 lines (31 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using ScriptCs.Contracts;
namespace ScriptCs
{
public class ScriptEnvironment : IScriptEnvironment
{
private readonly IConsole _console;
private readonly Printers _printers;
public ScriptEnvironment(string[] scriptArgs, IConsole console, Printers printers)
{
_console = console;
_printers = printers;
ScriptArgs = scriptArgs;
}
public IReadOnlyList<string> ScriptArgs { get; private set; }
public void AddCustomPrinter<T>(Func<T, string> printer)
{
_console.WriteLine("Adding custom printer for " + typeof(T).Name);
_printers.AddCustomPrinter<T>(printer);
}
public void Print(object o)
{
_console.WriteLine(_printers.GetStringFor(o));
}
public void Print<T>(T o)
{
_console.WriteLine(_printers.GetStringFor<T>(o));
}
}
}