-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathScriptEnvironment.cs
More file actions
57 lines (47 loc) · 1.58 KB
/
ScriptEnvironment.cs
File metadata and controls
57 lines (47 loc) · 1.58 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ScriptCs.Contracts;
namespace ScriptCs
{
public class ScriptEnvironment : IScriptEnvironment
{
private readonly IConsole _console;
private readonly Printers _printers;
private readonly IScriptInfo _scriptInfo;
public ScriptEnvironment(string[] scriptArgs, IConsole console, Printers printers, IScriptInfo scriptInfo = null )
{
_console = console;
_printers = printers;
_scriptInfo = scriptInfo;
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));
}
public string ScriptPath => _scriptInfo.ScriptPath;
public string[] LoadedScripts => _scriptInfo.LoadedScripts.ToArray();
public Assembly ScriptAssembly { get; private set; }
private bool _initialized;
public void Initialize()
{
if (!_initialized)
{
ScriptAssembly = Assembly.GetCallingAssembly();
_initialized = true;
}
}
}
}