dotnet/roslyn

Add Script property to InteractiveScriptGlobals and CommandLineScriptGlobals that returns a ScriptContext object

Open

#5.979 geöffnet am 14. Okt. 2015

Auf GitHub ansehen
 (17 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-InteractiveInteractive-ScriptingLogichelp wanted

Repository-Metriken

Stars
 (20.414 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

public class CommandLineScriptGlobals 
{
   public ScriptContext Script { get; }

   public CommandLineScriptGlobals(..., ScriptContext context)
}

public class InteractiveScriptGlobals 
{
   public ScriptContext Script { get; }

   public InteractiveScriptGlobals(..., ScriptContext context)
}

public class ScriptContext 
{
   public string GetPath([CallerFilePath]string path = null) { get; }
   public string GetDirectory([CallerFilePath]string path = null) { get; }

   public ScriptContext(string path)
}

The Script property would thus be available to scripts:

foreach (var arg in Script.Args) 
   Console.Writeline(File.ReadAllText(Path.Combine(Script.GetDirectory(), arg)));
...

In future we can add more features to this context:

class ScriptContext 
{
    Task<object> EvalAsync(string code, object globals);
}

F# has a similar concept: "fsi" object:

image

Contributor Guide