Skip to content

Commit

Permalink
allowed predefined references from file
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed May 27, 2019
1 parent a370623 commit a495c46
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/ICSharpCore/Script/InteractiveScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,22 @@ public class InteractiveScriptEngine

private string _currentDirectory;

private string[] _references;

public InteractiveScriptEngine(string currentDir, ILogger logger)
{
_currentDirectory = currentDir;
_logger = logger;

_scriptOptions = CreateScriptOptions();

var referencesFile = Path.Combine(Directory.GetCurrentDirectory(), "refs.txt");

if (File.Exists(referencesFile))
{
_references = File.ReadAllLines(referencesFile, Encoding.UTF8);
}

_runtimeDependencyResolver = new RuntimeDependencyResolver((t) => (level, m, e) =>
{
logger.Log(MapLogLevel(level), m, e);
Expand Down Expand Up @@ -85,6 +94,15 @@ public async Task<object> ExecuteAsync(string statement)
"using static ICSharpCore.Primitives.DisplayDataEmitter;"
};

var refsFromFile = string.Empty;

var references = _references;

if (references != null && references.Any())
{
usingStatements = references.Union(usingStatements).ToArray();
}

_scriptState = await CSharpScript.RunAsync(string.Join("\r\n", usingStatements), _scriptOptions, globals: _globals);
_scriptState = await _scriptState.ContinueWithAsync(statement, _scriptOptions);
}
Expand Down

0 comments on commit a495c46

Please sign in to comment.